Skip to content

Commit

Permalink
[flow analysis] Update the spec to match implementation of ==. (#4284)
Browse files Browse the repository at this point in the history
In fully sound null safety mode, flow analysis should know that a test
like `expr == null` is guaranteed to evaluate to `false` if the static
type of `expr` is non-nullable. But in unsound null safety mode, no
such guarantee can be made.

Since support for unsound null safety was only recently removed from
the CFE (see
dart-lang/sdk@0060b0f),
flow analysis still conservatively assumes that an expression with a
non-nullable static type might, nonetheless, still be `null`.

This change updates the spec to match the implementation in this
regard, and adds a reference to
#3100, where we are
discussing the possibility of changing the behavior.
  • Loading branch information
stereotype441 authored Mar 5, 2025
1 parent 5226bc7 commit 1b4215a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions resources/type-system/flow-analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,12 @@ then they are all assigned the same value as `after(N)`.
- Let `false(N) = unreachable(after(E2))`.
- Otherwise, if `equivalentToNull(T1)` and `T2` is non-nullable, or
`equivalentToNull(T2)` and `T1` is non-nullable, then:
- Let `true(N) = unreachable(after(E2))`.
- Let `false(N) = after(E2)`.
- Let `after(N) = after(E2)`.
- *Note that now that Dart no longer supports unsound null safety mode, it
would be sound (and probably preferable) to let `true(N) =
unreachable(after(E2))` and `false(N) = after(E2)`. This improvement is
being contemplated as part of
https://github.com/dart-lang/language/issues/3100.*
- Otherwise, if `stripParens(E1)` is a `null` literal, then:
- Let `true(N) = after(E2)`.
- Let `false(N) = promoteToNonNull(E2, after(E2))`.
Expand Down

0 comments on commit 1b4215a

Please sign in to comment.