Skip to content

Hashtable literal parsing fails when using an if statement as value #6970

@daxian-dbw

Description

@daxian-dbw

If there are other elements after the if() {} part, then parser will fail.
But it's fine if you have if() {} else {} as the value.

Steps to reproduce

$script = @'
@{
 a = if($true) { 'true' }
 b = 10
}
'@
$er = $null
$a = [System.Management.Automation.Language.Parser]::ParseInput($script, [ref]$null, [ref]$er)
$er

Expected behavior

$er is null. No error produced.

Actual behavior

Extent ErrorId              Message                                                    IncompleteInput
------ -------              -------                                                    ---------------
       MissingEndCurlyBrace Missing closing '}' in statement block or type definition.           False
b      UnexpectedToken      Unexpected token 'b' in expression or statement.                     False
}      UnexpectedToken      Unexpected token '}' in expression or statement.                     False

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.1
PSEdition                      Core
GitCommitId                    v6.0.1
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions