mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix parsing for array literals in index expressions in method calls (#19224)
This commit is contained in:
@@ -7962,7 +7962,18 @@ namespace System.Management.Automation.Language
|
||||
// G primary-expression '[' new-lines:opt expression new-lines:opt ']'
|
||||
|
||||
SkipNewlines();
|
||||
ExpressionAst indexExpr = ExpressionRule();
|
||||
bool oldDisableCommaOperator = _disableCommaOperator;
|
||||
_disableCommaOperator = false;
|
||||
ExpressionAst indexExpr = null;
|
||||
try
|
||||
{
|
||||
indexExpr = ExpressionRule();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_disableCommaOperator = oldDisableCommaOperator;
|
||||
}
|
||||
|
||||
if (indexExpr == null)
|
||||
{
|
||||
// ErrorRecovery: hope we see a closing bracket. If we don't, we'll pretend we saw
|
||||
|
||||
@@ -665,6 +665,15 @@ Describe "Parsing using statement with alias and linebreak and comma" -Tag CI {
|
||||
}
|
||||
}
|
||||
|
||||
It "Should correctly parse array literals for index expressions in method calls" {
|
||||
$tks = $null
|
||||
$ers = $null
|
||||
$Script = '[string]::join(" ", (0, 1, 2)[0, 1])'
|
||||
$result = [System.Management.Automation.Language.Parser]::ParseInput($Script, [ref]$tks, [ref]$ers)
|
||||
$result.EndBlock.Statements[0].PipelineElements[0].Expression.Arguments[1].Index.Elements.Count | Should -Be 2
|
||||
$ers.Count | Should -Be 0
|
||||
}
|
||||
|
||||
It "Should correctly parse array types that are used as arguments without brackets in generic type" {
|
||||
$tks = $null
|
||||
$ers = $null
|
||||
|
||||
Reference in New Issue
Block a user