Skip to content

Commit b7e86ca

Browse files
authored
remove mention of concrete variables, simplify rules around variable augmentation (#3333)
1 parent 529077c commit b7e86ca

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

working/augmentation-libraries/feature-specification.md

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -494,23 +494,31 @@ More specifically:
494494
`augment super =` expression invokes the original setter.
495495

496496
* **Augmenting a getter and/or setter with a variable:** This is a
497-
compile-time error in all cases. We may decide in the future to allow
498-
augmenting abstract or external getters and setters with variables, but for
499-
now you can instead use the following workaround:
497+
compile-time error in all cases. Augmenting an abstract or external variable
498+
with a variable is also a compile-time error, as those are actually just
499+
syntax sugar for getter/setter pairs and do not have an initializer that you
500+
can augment.
501+
502+
We may decide in the future to allow augmenting abstract or external
503+
getters, setters, or variables with variables, but for now you can instead
504+
use the following workaround:
500505

501506
- Add a new field.
502507
- Augment the getter and/or setter to delegate to that field.
503508

504-
If a concrete variable is augmented by a getter or setter, you **can** still
505-
augment the variable, as you are only augmenting the initializer. This is
506-
not considered to be augmenting the augmenting getter or setter, since those
507-
are not actually altered.
509+
If a non-abstract, non-external variable is augmented by a getter or setter,
510+
you **can** still augment the variable, as you are only augmenting the
511+
initializer of the original variable. This is not considered to be
512+
augmenting the augmenting getter or setter, since those are not actually
513+
altered.
514+
515+
The reason for this compile time error is that whether a member declaration
516+
is a field versus a getter/setter is a visible property of the declaration:
508517

509-
The reason for this is that whether a member declaration is a field versus a
510-
getter/setter is a visible property of the declaration: It determines
511-
whether the member can be initialized in a constructor initializer list. It
512-
is also a visible distinction when introspecting on a program with the
513-
analyzer, macros, or mirrors.
518+
- It determines whether the member can be initialized in a constructor
519+
initializer list.
520+
- It is also a visible distinction when introspecting on a program with the
521+
analyzer, macros, or mirrors.
514522

515523
When a declaration is augmented, we don't want the augmentation to be able
516524
to change any of the known properties of the existing member being
@@ -520,23 +528,15 @@ More specifically:
520528
it. Augmenting a field with a getter/setter doesn't change that property so
521529
it is allowed.
522530

523-
* **Augmenting a variable with a variable:** When augmenting a variable with
524-
a variable, the behavior differs depending on whether the original variable
525-
has a concrete implementation or not. Note that this concrete implementation
526-
could be one that is filled in by a compiler or other external source, if
527-
the declaration is marked `external`.
531+
* **Augmenting a variable with a variable:** Augmenting a variable with a
532+
variable only alters its initializer. External and abstract variables cannot
533+
be augmented with variables, because they have no initializer to augment.
528534

529-
If the variable being augmented _does not_ have a concrete implementation,
530-
then it gets one from the augmenting variable. This includes the backing
531-
store, the implicit getter and setter, as well as the initializer if
532-
present.
533-
534-
If the variable being augmented _does_**_ have a concrete implementation,
535-
then only the initializer has any meaning, and it replaces the original
536-
initializer. In this case the augmenting initializer may use an
535+
Since the initializer is the only meaningful part of the augmenting
536+
declaration, an initializer must be provided. This augmenting initializer
537+
replaces the original initializer. The augmenting initializer may use an
537538
`augment super` expression which executes the original initializer
538-
expression when evaluated. Augmenting a concrete field with a field does not
539-
affect its backing store, getter, or setter.
539+
expression when evaluated.
540540

541541
The `late` property of a variable must always be consistent between the
542542
augmented variable and its augmenting variables.
@@ -558,7 +558,7 @@ It is a compile-time error if:
558558
assumed to have an implementation provided by another external source, and
559559
they will throw a runtime exception when called if not.
560560

561-
* An augmenting initializer uses `augment super` and the original declaration
561+
* An augmenting initializer uses `augment super` and the augmented variable
562562
is not a variable with an initializer.
563563

564564
* A final variable is augmented with a setter. (Instead, the augmentation
@@ -572,7 +572,9 @@ It is a compile-time error if:
572572

573573
* A non-`late` variable is augmented with a `late` variable.
574574

575-
* A concrete getter or setter are augmented by a variable.
575+
* A getter or setter are augmented by a variable.
576+
577+
* An abstract or external variable are augmented by a variable.
576578

577579
### Augmenting enum values
578580

0 commit comments

Comments
 (0)