Skip to content

Commit f5153f7

Browse files
authored
clarify some behavior around initializers (#4005)
Closes #3977 Closes #3725 - Specify that the implicit null initialization of nullable fields does not happen unless no augmentation adds an initializer. - Specify that variables which require an initializer do not have to define it initially - it may come from an augmentation.
1 parent d771145 commit f5153f7

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

working/augmentation-libraries/feature-specification.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Augmentations
22

33
4-
Version: 1.31 (see [Changelog](#Changelog) at end)
4+
Version: 1.32 (see [Changelog](#Changelog) at end)
55

66
Augmentations allow spreading your implementation across multiple locations,
77
both within a single file and across multiple files. They can add new top-level
@@ -575,6 +575,10 @@ declaration, and if not `final`, also an abstract setter declaration. An
575575
`external` setter. Unlike abstract declarations, they are considered to
576576
have a concrete implementation.
577577

578+
Variables which require an initializer expression (such as those which have a
579+
non-nullable type and are not marked `late`) need not initially be defined
580+
with one, as long as there exists some augmentation which supplies it.
581+
578582
Augmentations on variables, getters, and setters works mostly at the level of
579583
these separate capabilities. For example, augmenting a variable with a getter
580584
replaces the augmented variable's implicit getter body with the augmenting
@@ -650,10 +654,11 @@ More specifically:
650654
usual, external and abstract variables cannot augment their
651655
initializing expression, since it does not exist.*
652656

653-
Augmenting initializer expressions replace the augmented initializer. The
654-
augmenting initializer may use an `augmented` expression which executes the
655-
augmented initializer expression when evaluated. If no initializer is
656-
provided then the augmented initializer is not altered.
657+
Augmenting initializer expressions replace the augmented initializer (or
658+
provide one where none existed previously). The augmenting initializer
659+
may use an `augmented` expression which executes the augmented initializer
660+
expression (if present) when evaluated. If no initializer is provided then
661+
the augmented initializer is not altered.
657662

658663
The `late` property of a variable must always be consistent between the
659664
augmented variable and its augmenting variables.
@@ -683,7 +688,9 @@ It is a **compile-time error** if:
683688

684689
* An augmenting variable’s initializing expression uses `augmented`, and
685690
the stack of augmented declarations do not include a variable with an
686-
initializing expression.
691+
explicit initializing expression. For nullable fields, the implicit null
692+
initialization only happens if there is no explicit initializer after the
693+
entire stack of augmentations has been applied.
687694

688695
* A non-writable variable declaration is augmented with a setter. (Instead,
689696
the author can declare a *non-augmenting* setter that goes alongside the
@@ -1393,6 +1400,13 @@ to the augmentation.
13931400

13941401
## Changelog
13951402

1403+
### 1.32
1404+
1405+
* Specify that variables which require an initializer can have it defined
1406+
in any augmentation.
1407+
* Specify that the implicit null initialization is not applied until after
1408+
augmentation.
1409+
13961410
### 1.31
13971411

13981412
* Specify that it is an error to have a static and instance member with the

0 commit comments

Comments
 (0)