default:
doesn't trigger UNREACHABLE_SWITCH_CASE hint #54575
Closed
Description
Consider the following code:
sealed class A {}
class B extends A {}
class C extends A {}
String f(A x) {
switch (x) {
case B():
return 'B';
case C():
return 'C';
case _:
return 'Some other subclass of A (impossible)';
}
}
This produces the analyzer hint:
info - test.dart:11:5 - This case is covered by the previous cases. Try removing the case clause, or restructuring the preceding patterns. - unreachable_switch_case
Which seems reasonable.
However, if I replace case _:
with default:
, then the analyzer doesn't report any issues.
This seems wrong to me. case _:
and default:
have exactly the same runtime behavior. They should lead to the same hints.
Metadata
Assignees
Labels
A bug or feature request we're likely to work onIssues with the analyzer's implementation of the language specIssues with the analyzer's Warning codesUse area-analyzer for Dart analyzer issues, including the analysis server and code completion.Incorrect behavior (everything from a crash to more subtle misbehavior)