Skip to content

Commit 64c5b78

Browse files
committed
Address review comments
1 parent f4ff6c8 commit 64c5b78

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

resources/type-system/flow-analysis.md

+24-12
Original file line numberDiff line numberDiff line change
@@ -422,31 +422,43 @@ Definitions:
422422
- Otherwise, `T` is the last type in the `promoted` list.
423423

424424
- `demote(promoted, written)`, where `promoted` is a list of types and `written`
425-
is a type, is a list containing all types `T` from `promoted` such that
426-
`written <: T`. _In effect, this removes any type promotions that are not
427-
compatible with the `written` type._
425+
is a type, is a list obtained by deleting any elements from `promoted` that do
426+
not satisfy `written <: T`. _In effect, this removes any type promotions that
427+
are no longer valid after the assignment of a value of type `written`._
428428

429429
- `toi_promote(declared, demoted, tested, written)`, where `demoted` and
430430
`tested` are lists of types, and `declared` and `written` are types, is the
431431
list `promoted`, defined as follows. _("toi" stands for "type of interest".)_
432-
- Let `p1` be a set containing the following types:
432+
- Let `current = currentType(declared, demoted)`. _(This is the type of the
433+
variable after demotions, but before type of interest promotion.)_
434+
- If `written` and `current` are the same type, then `promoted` is
435+
`demoted`. _(No type of interest promotion is necessary in this case.)_
436+
- Otherwise _(when `written` is not `current`)_, let `p1` be a set containing
437+
the following types:
433438
- **NonNull**(`declared`), if it is not the same as `declared`.
434439
- For each type `T` in the `tested` list:
435440
- `T`
436-
- **NonNull**(`T`), if it is not the same as `T`.
441+
- **NonNull**(`T`)
437442

438443
_The types in `p1` are known as the types of interest._
439444
- Let `p2` be the set `p1 \ { currentType(declared, demoted) }` _(where `\`
440-
denotes set subtraction)_.
441-
- If the `written` type is in `p2`, then `promoted` is `[demoted,
442-
written]`. _Writing a value whose static type is a type of interest promotes
443-
to that type._
444-
- Otherwise:
445+
denotes set difference)_.
446+
- If the `written` type is in `p2`, and `written <: currentType(declared,
447+
demoted)`, then `promoted` is `[...demoted, written]`. _Writing a value
448+
whose static type is a type of interest promotes to that type._
449+
- _Since `written` is the type assigned to the variable (after type
450+
coercion), in non-erroneous code it is guaranteed to be a subtype of
451+
`declared`. And `toi_promote` is always applied to the result of `demote`,
452+
so all types in `demoted` are guaranteed to be supertypes of
453+
`written`. Therefore, the requirement that `written <:
454+
currentType(declared, demoted)` is automatically satisfied for
455+
non-erroneous code._
456+
- Otherwise _(when `written` is not in `p2`)_:
445457
- Let `p3` be the set of all types `T` in `p2` such that `written <: T <:
446458
currentType(declared, demoted)`.
447459
- If `p3` contains exactly one type `T` that is a subtype of all the others,
448-
then `promoted` is `[demoted, T]`. _Writing a value whose static type is
449-
a subtype of a type of interest promotes to that type of interest,
460+
then `promoted` is `[...demoted, T]`. _Writing a value whose static type
461+
is a subtype of a type of interest promotes to that type of interest,
450462
provided there is a single "best" type of interest available to promote
451463
to._
452464
- Otherwise, `promoted` is `demoted`. _If there is no single "best" type

0 commit comments

Comments
 (0)