Switch block - error thrown if comment is on the second line of a Switch block #16884

Open
opened 2026-01-31 05:26:05 +00:00 by claunia · 0 comments
Owner

Originally created by @thegraffix on GitHub (Feb 27, 2022).

Windows Terminal Version

1.11.3471.0

Windows Build Number

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      19041  1320

Steps to reproduce

Code example below taken directory from Microsoft

Error:

$day = 3
switch ( $day )
{
    # This comment will throw an error in WindowsTerminal.exe v1.11.3471.0 (but not in PowerShell.exe or the ISE)
    0 { $result = 'Sunday'    }
    1 { $result = 'Monday'    }
    2 { $result = 'Tuesday'   }
    3 { $result = 'Wednesday' }
    4 { $result = 'Thursday'  }
    5 { $result = 'Friday'    }
    6 { $result = 'Saturday'  }
}
$result

At line:2 char:2
+ {
+  ~
Missing condition in switch statement clause.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingSwitchConditionExpression

No error:

$day = 3
switch ( $day )
{
    0 { $result = 'Sunday'    }
    # This comment will not throw an error in WindowsTerminal.exe, nor PowerShell.exe, nor ISE
    1 { $result = 'Monday'    }
    2 { $result = 'Tuesday'   }
    3 { $result = 'Wednesday' }
    4 { $result = 'Thursday'  }
    5 { $result = 'Friday'    }
    6 { $result = 'Saturday'  }
}
$result
Wednesday

Also no error:

$day = 3
switch ( $day )
{   # This comment will not throw an error in WindowsTerminal.exe, nor PowerShell.exe, nor ISE
    0 { $result = 'Sunday'    }
    1 { $result = 'Monday'    }
    2 { $result = 'Tuesday'   }
    3 { $result = 'Wednesday' }
    4 { $result = 'Thursday'  }
    5 { $result = 'Friday'    }
    6 { $result = 'Saturday'  }
}
$result
Wednesday

Expected Behavior

I expect Windows Terminal to allow a comment on the second line of the block since PowerShell.exe (5.1) and the ISE (v10.0.19041.1) allow it.

Actual Behavior

This error is thrown:

At line:2 char:2
+ {
+  ~
Missing condition in switch statement clause.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingSwitchConditionExpression
Originally created by @thegraffix on GitHub (Feb 27, 2022). # Windows Terminal Version 1.11.3471.0 # Windows Build Number ``` Major Minor Build Revision ----- ----- ----- -------- 10 0 19041 1320 ``` # Steps to reproduce [Code example](https://docs.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-switch?view=powershell-5.1) below taken directory from Microsoft Error: ``` $day = 3 switch ( $day ) { # This comment will throw an error in WindowsTerminal.exe v1.11.3471.0 (but not in PowerShell.exe or the ISE) 0 { $result = 'Sunday' } 1 { $result = 'Monday' } 2 { $result = 'Tuesday' } 3 { $result = 'Wednesday' } 4 { $result = 'Thursday' } 5 { $result = 'Friday' } 6 { $result = 'Saturday' } } $result At line:2 char:2 + { + ~ Missing condition in switch statement clause. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingSwitchConditionExpression ``` No error: ``` $day = 3 switch ( $day ) { 0 { $result = 'Sunday' } # This comment will not throw an error in WindowsTerminal.exe, nor PowerShell.exe, nor ISE 1 { $result = 'Monday' } 2 { $result = 'Tuesday' } 3 { $result = 'Wednesday' } 4 { $result = 'Thursday' } 5 { $result = 'Friday' } 6 { $result = 'Saturday' } } $result Wednesday ``` Also no error: ``` $day = 3 switch ( $day ) { # This comment will not throw an error in WindowsTerminal.exe, nor PowerShell.exe, nor ISE 0 { $result = 'Sunday' } 1 { $result = 'Monday' } 2 { $result = 'Tuesday' } 3 { $result = 'Wednesday' } 4 { $result = 'Thursday' } 5 { $result = 'Friday' } 6 { $result = 'Saturday' } } $result Wednesday ``` # Expected Behavior I expect Windows Terminal to allow a comment on the second line of the block since PowerShell.exe (5.1) and the ISE (v10.0.19041.1) allow it. # Actual Behavior This error is thrown: ``` At line:2 char:2 + { + ~ Missing condition in switch statement clause. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingSwitchConditionExpression ```
claunia added the Needs-TriageResolution-ExternalNeeds-Tag-FixProduct-Powershell labels 2026-01-31 05:26:06 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#16884