File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,17 @@ private IEnumerable<DiagnosticRecord> AnalyzeScriptBlockAst(ScriptBlockAst scrip
135
135
// Only checks for the case where lhs is a variable. Ignore things like $foo.property
136
136
VariableExpressionAst assignmentVarAst = assignmentAst . Left as VariableExpressionAst ;
137
137
138
+ if ( assignmentVarAst == null )
139
+ {
140
+ // If the variable is declared in a strongly typed way, e.g. [string]$s = 'foo' then the type is ConvertExpressionAst.
141
+ // Therefore we need to the VariableExpressionAst from its Child property.
142
+ var assignmentVarAstAsConvertExpressionAst = assignmentAst . Left as ConvertExpressionAst ;
143
+ if ( assignmentVarAstAsConvertExpressionAst != null && assignmentVarAstAsConvertExpressionAst . Child != null )
144
+ {
145
+ assignmentVarAst = assignmentVarAstAsConvertExpressionAst . Child as VariableExpressionAst ;
146
+ }
147
+ }
148
+
138
149
if ( assignmentVarAst != null )
139
150
{
140
151
// Ignore if variable is global or environment variable or scope is function
You can’t perform that action at this time.
0 commit comments