Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/System.Management.Automation/engine/parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7941,7 +7941,18 @@ private ExpressionAst ElementAccessRule(ExpressionAst primaryExpression, Token l
// 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
Expand Down
9 changes: 9 additions & 0 deletions test/powershell/Language/Parser/Parsing.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down