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
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
Expected behavior
$eris null. No error produced.Actual behavior
Environment data