Missing dead code warning #60342
Labels
area-devexp
For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
model-exhaustiveness
Implementation of exhaustiveness checking
P2
A bug or feature request we're likely to work on
Consider the following program:
I just learned that the above switch expression does not give rise to a dead code warning. It is guaranteed that when the scrutinee
a
has static typeA
, the run-time type ofa
will matchB1()
orB2()
. This implies that theC()
case is dead code, in spite of the fact that there could be an object whose run-time type is a subtype ofA
and also a subtype ofC
(class D implements B1, C {}
could be declared in any library).A small experiment shows that the exhaustiveness is recognized already: Comment out
C() => 3
: No exhaustiveness error is reported for the switch. This implies that all additional cases will be dead.Could we emit a dead code warning in this case? It seems sound and useful.
Note, though, that the ordering is significant: If the
C() => 3
case is moved up to an earlier position then it is not impossible that it could be matched, and hence it isn't dead code.The text was updated successfully, but these errors were encountered: