When an expression with static type Never
is used as a condition, flow analysis sometimes forgets that the code path is unreachable.
#60265
Labels
area-dart-model
Use area-dart-model for issues related to packages analyzer, front_end, and kernel.
model-flow
Implementation of flow analysis in analyzer/cfe
Whenever an expression:
Never
,ExpressionInfo
object*,flow anaylsis forgets the fact that the code is unreachable is forgotten when analyzing the "true" and "false" branches of the conditional.
*Expressions are associated with an
ExpressionInfo
object whenever they might require special treatment by flow analysis. This includes reads of local variables (and parameters), property gets, boolean literals, null literals, conditional expressions, the expressionthis
, and any of the expressions produced by||
,&&
,is
,is!
,==
,!=
, and prefix!
.**A "conditional context" means the condition of an
assert
,do
,for
,if
, orwhile
, or a conditional expression, or an operand of||
,&&
, or prefix!
.For example, in this code:
The above conditions are met for the read of the variable
n
, so flow analysis erroneously considers both1
and2
to be reachable expressions, and hence it considers the remainder of the functionf
to be reachable too. Therefore, the analyzer fails to emit an "unreachable code" warning.Whereas in this code:
The above conditions are not met, because
(throw 0)
is not associated by flow analysis with anExpressionInfo
object. So she analyzer correctly reports "unreachable code" warnings.See dart-lang/language#4287 (comment) for more context.
I'll try to work on a fix for this in the next week or two.
The text was updated successfully, but these errors were encountered: