-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Description
Using a literal array of indices as an index expression breaks in method calls.
It looks like the , that's part of the array literal is misconstrued as a method-argument separator.
Steps to reproduce
[string]::join(' ', (0, 1, 2)[0, 1])Expected behavior
0 1
Actual behavior
At line:1 char:32
+ [string]::join(' ', (0, 1, 2)[0, 1])
+ ~
Missing ']' after array index expression.
At line:1 char:35
+ [string]::join(' ', (0, 1, 2)[0, 1])
+ ~
Missing ')' in method call.
At line:1 char:35
+ [string]::join(' ', (0, 1, 2)[0, 1])
+ ~
Unexpected token ']' in expression or statement.
At line:1 char:36
+ [string]::join(' ', (0, 1, 2)[0, 1])
+ ~
Unexpected token ')' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndSquareBracket
To make the command work, you currently have to enclose either the entire expression in (...):
[string]::join(' ', ((0, 1, 2)[0, 1])) # OKor just the array inside [...]:
[string]::join(' ', (0, 1, 2)[(0, 1)]) # OKor use a variable:
$a = 0, 1; [string]::join(' ', (0, 1, 2)[$a]) # OKAlso, a single index works as expected:
[string]::join(' ', (0, 1, 2)[0]) # OKUsing the -join operator makes the problem go away:
(0, 1, 2)[0, 1] -join ' ' # OKIn short: avoiding a , in the index expression is needed to make the problem go away; such a , appears to be mistaken for a method-argument separator.
Environment data
PowerShell Core v6.1.0-preview.2 on macOS 10.13.4
PowerShell Core v6.1.0-preview.2 on Ubuntu 16.04.4 LTS
PowerShell Core v6.1.0-preview.2 on Microsoft Windows 10 Pro (64-bit; Version 1709, OS Build: 16299.371)
Windows PowerShell v5.1.17134.48 on Microsoft Windows 10 Pro (64-bit; Version 1709, OS Build: 16299.371)Metadata
Metadata
Assignees
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime