Add on directive to switch as an alternative to case #106
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current
switch
directive is not recommended due to its fall-through behavior being regarded as error-prone. To solve this problem, we introduce a newon
directive as an alternative tocase
, which doesn't support fall-through. This new directive allows specifying multiple comma-separated conditions in order to address the primary motivator for using fall-through withcase
.Example
Using
case
:Using
on
:Details
case
andon
directives is disallowed and will fail.switch
contains anon
, then usingbreak
orcontinue
is not supported (applying to bothon
anddefault
). In this situation,break
andcontinue
will follow the behavior of the containing scope, e.g. of a containinglist
. This does mean that if someone accidentally usesbreak
withon
, they could potentially become confused.Additional Notes
on
is not used, the legacy behavior forcase
/default
is thatcontinue
will be treated asbreak
. If we wish to change this, then that work can be done separately.default
, the parser also allows it to appear before or betweencase
directives, but when usingon
thendefault
is only allowed after.