mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Exclude outvariable assignments within the same CommandAst when inferring variables (#25224)
This commit is contained in:
@@ -1197,6 +1197,12 @@ Describe "Type inference Tests" -tags "CI" {
|
||||
$res.Name | Should -Be System.String
|
||||
}
|
||||
|
||||
It 'Ignores assignment when a variable is declared and used within the same commandAst' {
|
||||
$variableAst = { Get-Random 2>variable:RandomError1 -InputObject ($RandomError1) }.Ast.FindAll({ param($a) $a -is [Language.VariableExpressionAst] }, $true) | select -Last 1
|
||||
$res = [AstTypeInference]::InferTypeOf($variableAst)
|
||||
$res.Count | Should -Be 0
|
||||
}
|
||||
|
||||
It 'Ignores the last assignment when a variable is reused' {
|
||||
$variableAst = { $x = New-Guid; $x = $x.Where{$_} }.Ast.FindAll({ param($a) $a -is [Language.VariableExpressionAst] }, $true) | select -Last 1
|
||||
$res = [AstTypeInference]::InferTypeOf($variableAst)
|
||||
|
||||
Reference in New Issue
Block a user