-
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
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
I have complex in-house module that started to fail to import on recent daily builds of PS 7.3. It is working correctly on PS 5.1 and PS 7.2.1 and on older daily builds of PS 7.3. I was able to narrow the offending code to the following:
Get-CimInstance -ClassName 'Win32_NetworkAdapterConfiguration' |
Where-Object -Property IPEnabled |
ForEach-Object {
[IPAddress]::Parse(
$_.IPSubnet[
[Array]::IndexOf($_.IPAddress, $_.IPAddress[0])
]
)
}Error:
ParserError: D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:6
Line |
6 | [Array]::IndexOf($_.IPAddress, $_.IPAddress[0])
| ~
| Missing ] at end of type token.
The fix is to enclose the [Array]::IndexOf($_.IPAddress, $_.IPAddress[0]) in extra pair of parentheses. Like so:
Get-CimInstance -ClassName 'Win32_NetworkAdapterConfiguration' |
Where-Object -Property IPEnabled |
ForEach-Object {
[IPAddress]::Parse(
$_.IPSubnet[
([Array]::IndexOf($_.IPAddress, $_.IPAddress[0]))
]
)
}But as I mentioned before the original code is working on PS 5.1, PS 7.2.1 and older daily builds of PS 7.3 so it has to be a recent change in the PS 7.3 code that is causing this.
Expected behavior
. .\Test.ps1
AddressFamily : InterNetwork
ScopeId :
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
IsIPv6Teredo : False
IsIPv6UniqueLocal : False
IsIPv4MappedToIPv6 : False
Address : 16777215
IPAddressToString : 255.255.255.0Actual behavior
. .\Test.ps1
ParserError: D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:6
Line |
6 | [Array]::IndexOf($_.IPAddress, $_.IPAddress[0])
| ~
| Missing ] at end of type token.Error details
Exception :
Type : System.Management.Automation.ParseException
Errors :
Extent :
ErrorId : EndSquareBracketExpectedAtEndOfType
Message : Missing ] at end of type token.
Extent :
ErrorId : MissingEndParenthesisInMethodCall
Message : Missing ')' in method call.
Extent : ]
ErrorId : UnexpectedToken
Message : Unexpected token ']' in expression or statement.
Extent : {
ErrorId : MissingEndCurlyBrace
Message : Missing closing '}' in statement block or type definition.
Extent : )
ErrorId : UnexpectedToken
Message : Unexpected token ')' in expression or statement.
Extent : }
ErrorId : UnexpectedToken
Message : Unexpected token '}' in expression or statement.
Message : At D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:6 char:11
+ [Array]::IndexOf($_.IPAddress, $_.IPAddress[0])
+ ~
Missing ] at end of type token.
At D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:6 char:52
+ [Array]::IndexOf($_.IPAddress, $_.IPAddress[0])
+ ~
Missing ')' in method call.
At D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:7 char:4
+ ]
+ ~
Unexpected token ']' in expression or statement.
At D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:3 char:17
+ ForEach-Object {
+ ~
Missing closing '}' in statement block or type definition.
At D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:8 char:3
+ )
+ ~
Unexpected token ')' in expression or statement.
At D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:9 char:2
+ }
+ ~
Unexpected token '}' in expression or statement.
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : At D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:6 char:11
+ [Array]::IndexOf($_.IPAddress, $_.IPAddress[0])
+ ~
Missing ] at end of type token.
At D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:6 char:52
+ [Array]::IndexOf($_.IPAddress, $_.IPAddress[0])
+ ~
Missing ')' in method call.
At D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:7 char:4
+ ]
+ ~
Unexpected token ']' in expression or statement.
At D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:3 char:17
+ ForEach-Object {
+ ~
Missing closing '}' in statement block or type definition.
At D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:8 char:3
+ )
+ ~
Unexpected token ')' in expression or statement.
At D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:9 char:2
+ }
+ ~
Unexpected token '}' in expression or statement.
HResult : -2146233087
CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : EndSquareBracketExpectedAtEndOfType
InvocationInfo :
ScriptLineNumber : 6
OffsetInLine : 11
HistoryId : -1
ScriptName : D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1
Line : [Array]::IndexOf($_.IPAddress, $_.IPAddress[0])
PositionMessage : At D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:6 char:11
+ [Array]::IndexOf($_.IPAddress, $_.IPAddress[0])
+ ~
PSScriptRoot : D:\Users\Bukem\Documents\PowerShell\SCRIPTS
PSCommandPath : D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
TargetSite :
Name : Create
DeclaringType : scriptblock
MemberType : Method
Module : System.Management.Automation.dll
Data : System.Collections.ListDictionaryInternal
Source : System.Management.Automation
HResult : -2146233087
StackTrace :
at System.Management.Automation.ScriptBlock.Create(Parser parser, String fileName, String fileContents) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\runtime\CompiledScriptBlock.cs:line 660
at System.Management.Automation.ExternalScriptInfo.ParseScriptContents(Parser parser, String fileName, String fileContents, Nullable`1 definingLanguageMode) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\ExternalScriptInfo.cs:line 263
at System.Management.Automation.ExternalScriptInfo.get_ScriptBlock() in D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\ExternalScriptInfo.cs:line 224
at System.Management.Automation.CommandDiscovery.CreateCommandProcessorForScript(ExternalScriptInfo scriptInfo, ExecutionContext context, Boolean useNewScope, SessionStateInternal sessionState) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\CommandDiscovery.cs:line 660
at System.Management.Automation.CommandDiscovery.CreateScriptProcessorForSingleShell(ExternalScriptInfo scriptInfo, ExecutionContext context, Boolean useLocalScope, SessionStateInternal sessionState) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\CommandDiscovery.cs:line 340
at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(CommandInfo commandInfo, CommandOrigin commandOrigin, Nullable`1 useLocalScope, SessionStateInternal sessionState) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\CommandDiscovery.cs:line 584
at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource) in D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\ExecutionContext.cs:line 666
at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext
context) in D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\runtime\Operations\MiscOps.cs:line 311
at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][]
commandRedirections, FunctionContext funcContext) in D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\runtime\Operations\MiscOps.cs:line 510
at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\CallInstruction.Generated.cs:line 608
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\ControlFlowInstructions.cs:line 341
CategoryInfo : ParserError: (:) [], ParseException
FullyQualifiedErrorId : EndSquareBracketExpectedAtEndOfType
InvocationInfo :
ScriptLineNumber : 6
OffsetInLine : 11
HistoryId : -1
ScriptName : D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1
Line : [Array]::IndexOf($_.IPAddress, $_.IPAddress[0])
PositionMessage : At D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1:6 char:11
+ [Array]::IndexOf($_.IPAddress, $_.IPAddress[0])
+ ~
PSScriptRoot : D:\Users\Bukem\Documents\PowerShell\SCRIPTS
PSCommandPath : D:\Users\Bukem\Documents\PowerShell\SCRIPTS\Test.ps1
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1Environment data
Name Value
---- -----
PSVersion 7.3.0-preview.1
PSEdition Core
GitCommitId 7.3.0-preview.1-56-g30eac0a11e3479cf4feac76c7fa4b8d621eaabe2
OS Microsoft Windows 10.0.19044
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Enabled experimental features:
Get-ExperimentalFeature | Select-Object Name, Enabled
Name Enabled
---- -------
PSAMSIMethodInvocationLogging False
PSAnsiRenderingFileInfo False
PSCleanBlock True
PSCommandNotFoundSuggestion False
PSExec False
PSLoadAssemblyFromNativeCode True
PSNativeCommandArgumentPassing True
PSNativeCommandErrorActionPreference True
PSNativePSPathResolution True
PSRemotingSSHTransportErrorHandling True
PSStrictModeAssignment True
PSSubsystemPluginModel True
PSDesiredStateConfiguration.InvokeDscResource TrueVisuals
No response
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