Tor said:
The compiler's rule enforces that the types match.
Using enums in switch statements is exactly equivalent to using their
literals in a "normal" switch statement. And the range of an enum is its
values: It's pointless to even add a hint of ambiguity by allowing other
constant expressions than the enum's synthesized instances.
Agreed. The only question I'm asking is why the language prohibits
correct qualification of the instance name. Why can't one use
"Things.ONE", where "Things" is the type of the enum expression in the
switch, and "ONE" is one of its value identifiers?
This is not about what expressions can be used in the case, just about
what syntax is permitted in naming them.
I can imagine situations in which human readability would be improved by
allowing qualification.
For example, suppose two enums, designed separately, use the same
instance identifier with different meanings. The compiler will always
remember the type of the switch expression, and pick the right "ONE"
based on that. A human might see "ONE" and think "Widget.ONE" even if it
should be "Things.ONE", especially if the rest of the uses of "ONE" in
the class are "Widget.ONE".
Patricia