language
language copied to clipboard
Surprising flow-analysis of `switch` statements
The rule about switch statements is here. Consider the following example:
enum Enum { one, two }
void main() {
Enum e = Enum.one;
num n;
switch (e) {
case Enum.one: n = 1; break;
case Enum.two: n = 2; break;
}
print(n.isEven);
}
The switch statement rule might need a few adjustments (saying something about default
, and handling the situation where there is no default
and the last case has no break;
), but I would in any case expect the rule to promote n
to int
after the switch statement. The actual flow analysis does not reach that conclusion, so the analyzer reports an error on n.isEven
, showing that n
has type num
.
@stereotype441, what do you think?