Skip to content

Reports Missing closing '}' on a if statement when not all on one line or the { not on the next line with powershell version 5 #5297

@BenHuns

Description

@BenHuns

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

When running the following simple script:
`$ben = $true

if ($ben) {
Write-Output "ben"
}
`

the extension throws this error:

Missing closing '}' in statement block or type definition.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndCurlyBrace

if the script looks like this:
`$ben = $true

if ($ben)
{
Write-Output "ben"
}`

or this:
`$ben = $true

if ($ben) { Write-Output "ben" }
`

it works.
Or if I switch to version 7 of powershell.

PowerShell Version

Name                           Value                                                                                   
----                           -----                                                                                   
PSVersion                      5.1.26100.6584                                                                          
PSEdition                      Desktop                                                                                 
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                 
BuildVersion                   10.0.26100.6584                                                                         
CLRVersion                     4.0.30319.42000                                                                         
WSManStackVersion              3.0                                                                                     
PSRemotingProtocolVersion      2.3                                                                                     
SerializationVersion           1.1.0.1

Visual Studio Code Version

1.105.1
x64

Extension Version

Steps to Reproduce

see description

Visuals

No response

Logs

No logs

Image

Log level set to trace:

Image

found these
ms-vscode.powershell.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugA bug to squash.Needs: TriageMaintainer attention needed!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions