enum E {
one,
two,
three
}
main() {
E? e = E.three;
switch (e) { // error - Type 'E?' of the switch expression isn't assignable to the type 'E' of case expressions
case E.one:
true;
break;
case E.two:
false;
break;
default:
42;
}
}
Error suggests what is wrong.
It's the run-time type of the case expression constants which must be subtypes of the static type of e, not the other way around.
Consider the following code
Tested on
dartanalyzer version 2.8.0-dev.6.0