diff --git a/Engine/Helper.cs b/Engine/Helper.cs index a3009a7ef..131ab6b77 100644 --- a/Engine/Helper.cs +++ b/Engine/Helper.cs @@ -1093,8 +1093,8 @@ public string GetTypeFromMemberExpressionAst(MemberExpressionAst memberAst, Ast if (details != null && classes != null) { - // Get the class that corresponds to the name of the type (if possible) - psClass = classes.FirstOrDefault(item => String.Equals(item.Name, details.Type.FullName, StringComparison.OrdinalIgnoreCase)); + // Get the class that corresponds to the name of the type (if possible, the type is not available in the case of a static Singleton) + psClass = classes.FirstOrDefault(item => String.Equals(item.Name, details.Type?.FullName, StringComparison.OrdinalIgnoreCase)); } #endif diff --git a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 index ed71a57d2..158af4603 100644 --- a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 +++ b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 @@ -630,5 +630,12 @@ Describe "Test -EnableExit Switch" { $warnings.RuleName | Should -Be 'TypeNotFound' } } + + Describe "Handles static Singleton (issue 1182)" { + It "Does not throw or return diagnostic record" { + $scriptDefinition = 'class T { static [T]$i }; function foo { [CmdletBinding()] param () $script:T.WriteLog() }' + Invoke-ScriptAnalyzer -ScriptDefinition $scriptDefinition -ErrorAction Stop | Should -BeNullOrEmpty + } + } } }