-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Proposal: Exchange _
for ...
in exhaustive enums
#4859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We could change the syntax within switch-statements to something like this:
This way, we woudn't have the |
I said this on Discord, but it bears repeating:
Unlike It also only works on non-exhaustive enums so it'd compile error if you were trying to match a range, right? - (Since ranges must always have specified bounds.) |
Just a note, for switches using underscore as a catch all match in switches is a common convention in other languages, especially those with pattern matching. |
@ityonemo |
Not sure it means much, but I extend my support for this! |
another option that crossed my mind is adding a keyword similar to nonexhaustive enum(u8) {
a = 0,
b = 1,
} which declares the union type upfront instead of having to scan to the end. |
Follow-up on a discussion with @Tetralux and others on Discord and an improvement for #2524:
The use of
_
in exhaustive enums does not communicate intent precisely as it's not clear if there is "something left out", only one item, multiple items. It's not clear to a first-time reader what this symbol is telling us.The proposal is to exchange it for the ellipsis
...
which is already a token in Zig used in theswitch
range specification, but also is the commonly known symbol for stuff left out:The new syntax would be:
I think this communicates much more what is expressed here than the symbol
_
which tells the user that "something is ignored".The text was updated successfully, but these errors were encountered: