Skip to content

Commit e2433e1

Browse files
Flow analysis: promotion to Never makes code unreachable. (#1097)
See dart-lang/sdk#41981 Corresponding implementation change is here: https://dart-review.googlesource.com/c/sdk/+/154624
1 parent a82912d commit e2433e1

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

resources/type-system/flow-analysis.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,13 @@ Definitions:
430430
- otherwise `demoted` is `previous`
431431

432432
- `promote(E, T, M)` where `E` is an expression, `T` is a type which it may be
433-
promoted to, and `M = FlowModel(r, VI)` is the flow model in which to promote,
434-
is defined as follows:
435-
- If `E` is not a promotion target, then `M`
433+
promoted to, and `M1 = FlowModel(r, VI)` is the flow model in which to
434+
promote, is defined to be `M3`, where:
435+
- If `E` is not a promotion target, then `M3` = `M1`
436436
- If `E` is a promotion target `x`, then
437437
- Let `VM = VariableModel(declared, promoted, tested, assigned, unassigned,
438438
captured)` be the variable model for `x` in `VI`
439-
- If `x` is not promotable via type test to `T` given `VM`, then return `M`
439+
- If `x` is not promotable via type test to `T` given `VM`, then `M3` = `M1`
440440
- Else
441441
- Let `S` be the current type of `x` in `VM`
442442
- If `T <: S` then let `T1` = `T`
@@ -445,7 +445,8 @@ Definitions:
445445
- Else `x` is not promotable (shouldn't happen since we checked above)
446446
- Let `VM2 = VariableModel(declared, T1::promoted, T1::tested, assigned,
447447
unassigned, captured)`
448-
- Return `FlowModel(r, VI[x -> VM2])`
448+
- Let `M2 = FlowModel(r, VI[x -> VM2])`
449+
- If `T1 <: Never` then `M3` = `unreachable(M2)`, otherwise `M3` = `M2`
449450
- `promoteToNonNull(E, M)` where `E` is an expression and `M` is a flow model is
450451
defined to be `promote(E, T, M)` where `T0` is the type of `E`, and `T` is
451452
**NonNull(`T0`)**.

0 commit comments

Comments
 (0)