-
Notifications
You must be signed in to change notification settings - Fork 8.2k
The chain operators don't work with flow-control statements exit, return, and Throw #10967
Copy link
Copy link
Closed
Closed
Copy link
Labels
Committee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decisionIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Description
A common idiom (in the Bash world, which inspired PowerShell's && and || operators) is to conditionally exit a script when invocation of a command fails, along the lines of:
# Assume existence of /somepath and exit, if it doesn't exist.
ls /somepath || exit 1
Currently, neither exit nor return nor throw can be used on the RHS of && / ||
Steps to reproduce
{ Get-Item /nosuch || return } | Should -Not -Throw
{ Get-Item / && return } | Should -Not -ThrowExpected behavior
The tests should pass.
Actual behavior
The tests fail, because return is not recognized
Expected no exception to be thrown, but an exception
"The term 'return' is not recognized as the name of a
cmdlet, function, script file, or operable program. ..."...
Environment data
PowerShell Core 7.0.0-preview.6
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Committee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decisionIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime