@@ -422,31 +422,43 @@ Definitions:
422
422
- Otherwise, ` T ` is the last type in the ` promoted ` list.
423
423
424
424
- ` 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 ` ._
428
428
429
429
- ` toi_promote(declared, demoted, tested, written) ` , where ` demoted ` and
430
430
` tested ` are lists of types, and ` declared ` and ` written ` are types, is the
431
431
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:
433
438
- ** NonNull** (` declared ` ), if it is not the same as ` declared ` .
434
439
- For each type ` T ` in the ` tested ` list:
435
440
- ` T `
436
- - ** NonNull** (` T ` ), if it is not the same as ` T ` .
441
+ - ** NonNull** (` T ` )
437
442
438
443
_ The types in ` p1 ` are known as the types of interest._
439
444
- 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 ` )_ :
445
457
- Let ` p3 ` be the set of all types ` T ` in ` p2 ` such that `written <: T <:
446
458
currentType(declared, demoted)`.
447
459
- 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,
450
462
provided there is a single "best" type of interest available to promote
451
463
to._
452
464
- Otherwise, ` promoted ` is ` demoted ` . _ If there is no single "best" type
0 commit comments