Skip to content

Commit 32e2f61

Browse files
author
Quoc Truong
committed
Fix avoiduninitializedvariable not recognizing switchparameter
1 parent f7e7e47 commit 32e2f61

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Engine/VariableAnalysis.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private void ProcessParameters(IEnumerable<ParameterAst> parameters)
8686
type = paramAst.TypeName.GetReflectionType();
8787
}
8888

89-
if (String.Equals(paramAst.TypeName.FullName, "switch", StringComparison.OrdinalIgnoreCase))
89+
if (paramAst.TypeName.GetReflectionType() == typeof(System.Management.Automation.SwitchParameter))
9090
{
9191
isSwitchOrMandatory = true;
9292
}

Tests/Rules/AvoidGlobalOrUnitializedVarsNoViolations.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@ $proc[0]
3131

3232
function Test-PreferenceVariable
3333
{
34+
Param(
35+
[switch]
36+
$a,
37+
38+
[System.Management.Automation.SwitchParameter]
39+
$b
40+
)
3441

3542
if (-not $PSBoundParameters.ContainsKey('Verbose')) {
3643
$VerbosePreference = $PSCmdlet.GetVariableValue('VerbosePreference') -as
3744
[System.Management.Automation.ActionPreference]
3845
}
3946

4047
$VerbosePreference
41-
}
48+
}

0 commit comments

Comments
 (0)