mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix the regression when doing type inference for $_ (#21223)
This commit is contained in:
@@ -1983,8 +1983,19 @@ namespace System.Management.Automation
|
||||
{
|
||||
if (switchErrorStatement.Conditions?.Count > 0)
|
||||
{
|
||||
parent = switchErrorStatement.Conditions[0];
|
||||
if (switchErrorStatement.Conditions[0].Extent.EndOffset < variableExpressionAst.Extent.StartOffset)
|
||||
{
|
||||
parent = switchErrorStatement.Conditions[0];
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// $_ is inside the condition that is being declared, eg: Get-Process | Sort-Object -Property {switch ($_.Proc<Tab>
|
||||
parent = switchErrorStatement.Parent;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else if (parent is ScriptBlockExpressionAst)
|
||||
|
||||
@@ -1860,6 +1860,11 @@ class InheritedClassTest : System.Attribute
|
||||
$res.CompletionMatches[0].CompletionText | Should -BeExactly 'Black' # 0 = NonPositive
|
||||
}
|
||||
|
||||
It 'Tab completion of $_ inside incomplete switch condition' {
|
||||
$res = TabExpansion2 -inputScript 'Get-PSDrive | Sort-Object -Property {switch ($_.nam'
|
||||
$res.CompletionMatches[0].CompletionText | Should -Be 'Name'
|
||||
}
|
||||
|
||||
It "Test [CommandCompletion]::GetNextResult" {
|
||||
$inputStr = "Get-Command -Type Alias,c"
|
||||
$res = TabExpansion2 -inputScript $inputStr -cursorColumn $inputStr.Length
|
||||
|
||||
Reference in New Issue
Block a user