Skip to content

Commit c85bf65

Browse files
author
Quoc Truong
committed
Merge pull request #241 from PowerShell/FixAutomaticVariable
Fix matches and psversiontable not recognized by variableanalysis
2 parents e8b5cfe + 8d5eafe commit c85bf65

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Engine/SpecialVars.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ internal class SpecialVars
3434
internal const string PSScriptRoot = "PSScriptRoot";
3535
internal const string PSCommandPath = "PSCommandPath";
3636
internal const string ExecutionContext = "ExecutionContext";
37+
internal const string Matches = "Matches";
38+
internal const string PSVersionTable = "PSVersionTable";
3739

3840
internal static readonly string[] InitializedVariables;
3941

@@ -63,7 +65,9 @@ static SpecialVars()
6365
MyInvocation,
6466
PSScriptRoot,
6567
PSCommandPath,
66-
ExecutionContext
68+
ExecutionContext,
69+
Matches,
70+
PSVersionTable
6771
};
6872
internal static readonly Type[] AutomaticVariableTypes = new Type[]
6973
{
@@ -76,7 +80,9 @@ static SpecialVars()
7680
/* MyInvocation */ typeof(InvocationInfo),
7781
/* PSScriptRoot */ typeof(string),
7882
/* PSCommandPath */ typeof(string),
79-
/* ExecutionContext */ typeof(EngineIntrinsics),
83+
/* ExecutionContext */ typeof(EngineIntrinsics),
84+
/* Matches */ typeof(System.Collections.Hashtable),
85+
/* PSVersionTable */ typeof(System.Collections.Hashtable)
8086
};
8187

8288

Tests/Rules/AvoidGlobalOrUnitializedVarsNoViolations.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ function Test {
99

1010
$a = 3;
1111

12+
"hi there!" -match "hi" | Out-Null;
13+
$matches[0];
14+
15+
$PSVersionTable;
16+
1217
if ($true) {
1318
$a = 4;
1419
$c = 3;

0 commit comments

Comments
 (0)