Files
sdk/pkg/_fe_analyzer_shared/test
Paul Berry f835846705 Flow analysis: add support for promotion of cached values.
Implement the necessary flow analysis bookkeeping so that in a pattern
of the form `P1 && P2`, any type checks performed by `P1` will be
reflected in the matched value type used by `P2`.  To accomplish this,
we allocate a promotion key to represent the "cached value" matched by
every pattern and subpattern (so that `P1 && P2` promotes properly
even when in a subpattern of another pattern).  This promotion key is
stored (in the form of a `ReferenceWithType<Type>`) in the
`_PatternContext` class.

Also, move `_scrutineeReference` and `_scrutineeType` into
`_FlowAnalysisImpl`; this preserves the existing behaviour of
promoting the scrutinee expression, but with less bookkeeping (since
we don't need to pass it along from one context to the next).  And add
`_FlowAnalysisImpl._scrutineeSsaReference` so that if the scrutinee is
modified during execution of the switch statement, it won't be
erroneously promoted by patterns that follow.

Finally, implement some preliminary logic for `||` patterns to avoid
breaking existing tests.  I will fill this out (and test it
thoroughly) in a follow-up CL.

Bug: https://github.com/dart-lang/sdk/issues/50419
Change-Id: I0d934e706ad5b19cda46a198afb2fb7a4309829b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275788
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-12-16 21:11:25 +00:00
..
2022-09-16 19:35:00 +00:00