Skip to content

Commit 1b4215a

Browse files
[flow analysis] Update the spec to match implementation of ==. (#4284)
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.
1 parent 5226bc7 commit 1b4215a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

resources/type-system/flow-analysis.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,12 @@ then they are all assigned the same value as `after(N)`.
558558
- Let `false(N) = unreachable(after(E2))`.
559559
- Otherwise, if `equivalentToNull(T1)` and `T2` is non-nullable, or
560560
`equivalentToNull(T2)` and `T1` is non-nullable, then:
561-
- Let `true(N) = unreachable(after(E2))`.
562-
- Let `false(N) = after(E2)`.
561+
- Let `after(N) = after(E2)`.
562+
- *Note that now that Dart no longer supports unsound null safety mode, it
563+
would be sound (and probably preferable) to let `true(N) =
564+
unreachable(after(E2))` and `false(N) = after(E2)`. This improvement is
565+
being contemplated as part of
566+
https://github.com/dart-lang/language/issues/3100.*
563567
- Otherwise, if `stripParens(E1)` is a `null` literal, then:
564568
- Let `true(N) = after(E2)`.
565569
- Let `false(N) = promoteToNonNull(E2, after(E2))`.

0 commit comments

Comments
 (0)