-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
proposal: enum switch narrowing #12863
Comments
Related: #7224 |
what would |
a custom version of to get the non-narrowed version you would reference |
This could also work for integer ranges along with certain forms of Though this would mean tracking range information within the type system (a bit like the any range integer proposal). |
Right, and what would
where |
no it would be as if the enum had been defined inline the other way to implement this, is to keep it of type |
But then how do you implement the coercion from the narrowed type to the super-type? |
|
This doesn't really answer the question. If
|
ah, interesting catch. then implementation option b would probably be better, so long as the compile error was informative edit: similar to the error you get with this code: const E = enum { a, b };
test {
var foo: E = .a;
switch (foo) {
.a => {},
.a => {},
.b => {},
}
}
but handling |
I'd like to see this applied to const E = enum { a, b, c };
var e: E = .a;
switch (e) {
.a => {},
inline .b, .c => |_, tag| switch (tag) {
.b, .c => {},
},
} Today this is an error that |
Zig Version
0.10.0-dev.3998+c25ce5bba
Steps to Reproduce
Expected Behavior
successful build / run
Actual Behavior
The text was updated successfully, but these errors were encountered: