Flow analysis fails to record types of interest when an is
expression is not used in a conditional context
#60479
Labels
area-dart-model
For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.
model-flow
Implementation of flow analysis in analyzer/cfe
P3
A lower priority bug or feature request
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
Consider the following code (from dart-lang/co19#3126 (comment)):
According to the flow analysis spec:
true(s is T)
should add the typeT
to thetested
list in theVariableModel
fors
.after(N)
foris
expressions, the general ruleafter(N) = join(true(N), false(N))
should be used (see the Expressions subsection).join
is based onjoinV
, and the definition ofjoinV
(see the Models subsection) says thatjoinV
takes the union of thetested
lists from the two branches.after(s is T)
should includeT
as one of thetested
types fors
. (In other words,T
should be a type of interest fors
after thisis
check).What's happening instead is that instead of using the general rule
after(N) = join(true(N), false(N))
foris
expressions, flow analysis is failing to update its description of the_current
flow state, so in effect what the implementation is doing is this (I've highlighted the difference from the spec in bold):In practice this is pretty benign because most of the time people perform
is
tests, they do so in a conditional context, so the flow models that get propagated forward come fromtrue(N)
andfalse(N)
(which are behaving correctly). The incorrect behavior only happens if theis
test isn't used in a condition, so the flow model that gets propagated forward come from the buggyafter(N)
.Since the bug only manifests if an
is
test is used in an unusual way, and only causes problems with types of interest, I'm classifying this as a P3. I will still try to get to fixing it though.The text was updated successfully, but these errors were encountered: