Open momumi opened 4 years ago
Adding to this proposal, the payload should contain a subset of the enum values such that it can be checked exhaustively:
const X = enum {A, B, C, D, E};
switch(x) {
.A, .E => |vowel| switch(vowel) {
.A => {},
else => {} //ok, handles other cases
},
.B .. .D => |cons| switch (cons) {
.B => {},
.D => {},
} // error, doesnt handle .C
}
I think that this could result in problems in many areas of code.
While the example of Key.A ... Key.Z
makes sense, something like Clubs ... Diamonds
does not as there is no ordering to playing card suits. I think that this is the case for most enums.
This could result in poor practices and fragile code - a maintainer of a package/library no longer has to just worry about the presence of enum values, but also the ordering.
This issue can be closed in favor of #15556 , which also contains a counter proposal
When using a switch statement to match against enums, it would be nice to be able to match against a range of enum values eg:
Currently you can get this to work using
@enumToInt
like this:But this is not perfect though because I need to add
else => unreachable
, hence I won't get error messages if I update the enum and forget to add the new values to the switch statement.