You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
switch statement unexpectedly treats barewords as expandable strings #3668
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Languageparser, language semantics
Note: It may be too late to change this behavior, or it may fall into Bucket 3: Unlikely Grey Area.
If the former, the pitfall discussed is at least worth documenting.
about_Switch states about the syntax of individual switch branches:
The above suggests that an expression can only be used inside script blocks, but in practice you can also use (...)- and $(...)-enclosed expressions directly (e.g., (1 + 2)) and even method calls (e.g., $PSVersionTable.PSVersion.ToString()).
Surprisingly, however, a non-numeric unquoted token that doesn't start with ( or $ (and doesn't break parsing) is unexpectedly treated like an (expandable) string rather than as an expression:
That is, unquoted [uint32]::MinValue is interpreted the same way as '[uint32]::MinValue' in this case.
This is unexpected, given that it is reasonable to conceive of the branch conditions of a switch statement as the RHS of an expression along the lines of <switch-value> -eq <branch-condition>, and given that any unquoted token on the RHS of -eq is interpreted as an expression.
Environment data
PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on Darwin Kernel Version 16.5.0: Fri Mar 316:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64
changed the title [-]`switch` statement unexpectedly treats barewords as string literals[/-][+]`switch` statement unexpectedly treats barewords as expandable strings[/+]on May 1, 2017
PowerShell ISE makes this pretty easy to see what is going on, and I have implemented this in PowerShell/EditorSyntax#156. The condition is treated as an argument, not an expression. I think the documentation for this needs to be clarified, though not sure how.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 23, 2023
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Languageparser, language semantics
Activity
[-]`switch` statement unexpectedly treats barewords as string literals[/-][+]`switch` statement unexpectedly treats barewords as expandable strings[/+]msftrncs commentedon Mar 12, 2019
PowerShell ISE makes this pretty easy to see what is going on, and I have implemented this in PowerShell/EditorSyntax#156. The condition is treated as an argument, not an expression. I think the documentation for this needs to be clarified, though not sure how.
Source: https://github.com/msftrncs/PwshReadXmlPList/blob/master/PList%20Reader.ps1
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.