Skip to content

Commit

Permalink
clarify some behavior around initializers (#4005)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jakemac53 authored Aug 1, 2024
1 parent d771145 commit f5153f7
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions working/augmentation-libraries/feature-specification.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Augmentations

Author: rnystrom@google.com, jakemac@google.com, lrn@google.com <br>
Version: 1.31 (see [Changelog](#Changelog) at end)
Version: 1.32 (see [Changelog](#Changelog) at end)

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

Variables which require an initializer expression (such as those which have a
non-nullable type and are not marked `late`) need not initially be defined
with one, as long as there exists some augmentation which supplies it.

Augmentations on variables, getters, and setters works mostly at the level of
these separate capabilities. For example, augmenting a variable with a getter
replaces the augmented variable's implicit getter body with the augmenting
Expand Down Expand Up @@ -650,10 +654,11 @@ More specifically:
usual, external and abstract variables cannot augment their
initializing expression, since it does not exist.*

Augmenting initializer expressions replace the augmented initializer. The
augmenting initializer may use an `augmented` expression which executes the
augmented initializer expression when evaluated. If no initializer is
provided then the augmented initializer is not altered.
Augmenting initializer expressions replace the augmented initializer (or
provide one where none existed previously). The augmenting initializer
may use an `augmented` expression which executes the augmented initializer
expression (if present) when evaluated. If no initializer is provided then
the augmented initializer is not altered.

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

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

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

## Changelog

### 1.32

* Specify that variables which require an initializer can have it defined
in any augmentation.
* Specify that the implicit null initialization is not applied until after
augmentation.

### 1.31

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

0 comments on commit f5153f7

Please sign in to comment.