PowerShell / PowerShell/vscode-powershell

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

Open
#5,297 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Bug Needs: Triage
Dominant language
TypeScript
Stars
1.9k
Forks
547
PR merge metrics
No merged PRs in 30d

Description

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
ms-vscode.powershell@2025.4.0
Steps to Reproduce

see description

Visuals

No response

Logs

No logs

Image

Log level set to trace:

Image

found these
ms-vscode.powershell.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the three brace layouts in the issue with PowerShell 5.1 through the VS Code extension, then compare the diagnostics with PowerShell 7. The issue is done when the valid multi-line form no longer reports a missing closing brace while the existing working forms remain valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, typescript
Domain
developer-experience, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.