Skip to content

Commit 1a45dd2

Browse files
authored
change augment super to augmented (#3404)
1 parent a69420c commit 1a45dd2

File tree

1 file changed

+57
-52
lines changed

1 file changed

+57
-52
lines changed

working/augmentation-libraries/feature-specification.md

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ import augment 'b.dart';
210210
augment class C {}
211211
212212
augment void trace() {
213-
augment super.trace();
213+
augmented();
214214
print('a');
215215
}
216216
@@ -220,7 +220,7 @@ library augment 'a.dart';
220220
class D {}
221221
222222
augment void trace() {
223-
augment super.trace();
223+
augmented();
224224
print('b');
225225
}
226226
@@ -230,12 +230,12 @@ library augment 'main.dart';
230230
augment class D {}
231231
232232
augment void trace() {
233-
augment super.trace();
233+
augmented();
234234
print('c');
235235
}
236236
237237
augment void trace() {
238-
augment super.trace();
238+
augmented();
239239
print('d');
240240
}
241241
```
@@ -284,12 +284,11 @@ Often, an augmentation wants to also preserve and run the code of the original
284284
declaration it augments (hence the name "augmentation"). It may want run before
285285
the original code, after it, or both. To allow that, we allow a new expression
286286
syntax inside the bodies of augmenting members. Inside a member marked
287-
`augment`, an expression like `augment super` can be used to refer to the
288-
original function, getter, setter, or variable initializer. See the next
289-
section for a full specification of what `augment super` actually means,
290-
in the various contexts.
291-
292-
**TODO: I'm not sold on `augment super`. Is there a better syntax?**
287+
`augment`, the expression `augmented` can be used to refer to the original
288+
function, getter, setter, or variable initializer. This is a contextual keyword
289+
within `augment` members, and has no special meaning outside of that context.
290+
See the next section for a full specification of what `augmented` actually
291+
means, in the various contexts.
293292
294293
The same declaration can be augmented multiple times by separate augmentation
295294
libraries. When that happens, the merge order defined previously determines
@@ -304,39 +303,43 @@ It is a compile-time error if:
304303
original declaration occurs, according to merge order. *An augmentation
305304
library can both declare a new declaration and augment it in the same file.*
306305
307-
### Augment super
306+
### Augmented Expression
308307
309-
The exact result of an `augment super` expression depends on what is being
308+
The exact result of an `augmented` expression depends on what is being
310309
augmented, but it follows generally the same rules as any normal identifier:
311310
312-
* **Augmenting getters**: Within an augmenting getter `augment super` invokes
313-
the getter and evaluates to the return value. If augmenting a field with a
311+
* **Augmenting getters**: Within an augmenting getter `augmented` invokes the
312+
getter and evaluates to the return value. If augmenting a field with a
314313
getter, this will invoke the implicit getter from the augmented field.
315314
316-
* **Augmenting setters**: Within an augmenting setter `augment super` must be
315+
* **Augmenting setters**: Within an augmenting setter `augmented` must be
317316
followed by an `=` and will directly invoke the augmented setter. If
318317
augmenting a field with a setter, this will invoke the implicit setter from
319318
the augmented field.
320319
321-
* **Augmenting fields**: Within an augmenting field, `augment super` can only
322-
be used in an initializer expression, and refers to the original field's
320+
* **Augmenting fields**: Within an augmenting field, `augmented` can only be
321+
used in an initializer expression, and refers to the original field's
323322
initializer expression, which is immediately evaluated.
324323
325-
It is a compile-time error to use `augment super` in an augmenting field's
324+
It is a compile-time error to use `augmented` in an augmenting field's
326325
initializer if the member being augmented is not a field with an
327326
initializer.
328327
329-
* **Augmenting functions**: When augmenting a function, `augment super` refers
330-
to the augmented function. Tear offs are allowed.
328+
* **Augmenting functions**: When augmenting a function, `augmented` refers to
329+
the augmented function. Tear offs are not allowed, so this function must
330+
immediately be invoked.
331+
332+
* **Augmenting operators**: When augmenting an operator, `augmented` must be
333+
followed by the operator. For example when augmenting `+` you must do
334+
`augmented + 1`, and when augmenting `[]` you must do `augmented[<arg>]`.
335+
These constructs invoke the augmented operator, and are the only valid uses
336+
of `augmented` in these contexts.
331337
332-
* **Augmenting operators**: When augmenting an operator, `augment super` must
333-
be followed by the operator. For example when augmenting `+` you must do
334-
`augment super + 1`, and when augmenting `[]` you must do
335-
`augment super[<arg>]`. These constructs invoke the augmented operator, and
336-
are the only valid uses of `augment super` in these contexts.
338+
* **Augmenting enum values**: When augmenting an enum value, `augmented` has
339+
no meaning and is not allowed.
337340
338-
* **Augmenting enum values**: When augmenting an enum value, `augment super`
339-
has no meaning and is not allowed.
341+
In all relevant cases, if the augmented member is an instance member, it is
342+
invoked with the same value for `this`.
340343
341344
### Augmenting types
342345
@@ -414,23 +417,21 @@ augmented to wrap the original code in additional code:
414417
// Wrap the original function in profiling:
415418
augment int slowCalculation(int a, int b) {
416419
var watch = Stopwatch()..start();
417-
var result = augment super(a, b);
420+
var result = augmented(a, b);
418421
print(watch.elapsedMilliseconds);
419422
return result;
420423
}
421424
```
422425

423426
The augmentation replaces the original function body with the augmenting code.
424-
Inside the augmentation body, a special `augment super()` expression may be used
425-
to execute the original function body. That expression takes an argument list
427+
Inside the augmentation body, a special `augmented()` expression may be used to
428+
execute the original function body. That expression takes an argument list
426429
matching the original function's parameter list and returns the function's
427430
return type.
428431

429-
**TODO: Better syntax than `augment super`?**
430-
431-
The augmenting function does not have to pass the same arguments to `augment
432-
super()` as were passed to it. It may call it once, more than once, or not at
433-
all.
432+
The augmenting function does not have to pass the same arguments to
433+
`augmented()` as were passed to it. It may call it once, more than once, or not
434+
at all.
434435

435436
It is a compile-time error if:
436437

@@ -495,13 +496,13 @@ More specifically:
495496

496497
* **Augmenting with a getter:** A getter in an augmentation library can
497498
augment a getter in the main library or the implicit getter defined by a
498-
variable in the main library. Inside the augmenting body, an `augment super`
499+
variable in the main library. Inside the augmenting body, an `augmented`
499500
expression invokes the original getter.
500501

501502
* **Augmenting with a setter:** A setter in an augmentation library can
502503
augment a setter in the main library or the implicit setter defined by a
503504
non-final variable in the main library. Inside the augmenting setter, an
504-
`augment super =` expression invokes the original setter.
505+
`augmented =` expression invokes the original setter.
505506

506507
* **Augmenting a getter and/or setter with a variable:** This is a
507508
compile-time error in all cases. Augmenting an abstract or external variable
@@ -545,8 +546,8 @@ More specifically:
545546
Since the initializer is the only meaningful part of the augmenting
546547
declaration, an initializer must be provided. This augmenting initializer
547548
replaces the original initializer. The augmenting initializer may use an
548-
`augment super` expression which executes the original initializer
549-
expression when evaluated.
549+
`augmented` expression which executes the original initializer expression
550+
when evaluated.
550551

551552
The `late` property of a variable must always be consistent between the
552553
augmented variable and its augmenting variables.
@@ -563,13 +564,13 @@ It is a compile-time error if:
563564

564565
* The original and augmenting declarations do not have the same type.
565566

566-
* An augmenting declaration uses `augment super` when the original declaration
567-
has no concrete implementation. Note that all external declarations are
568-
assumed to have an implementation provided by another external source, and
569-
they will throw a runtime exception when called if not.
567+
* An augmenting declaration uses `augmented` when the original declaration has
568+
no concrete implementation. Note that all external declarations are assumed
569+
to have an implementation provided by another external source, and they will
570+
throw a runtime exception when called if not.
570571

571-
* An augmenting initializer uses `augment super` and the augmented variable
572-
is not a variable with an initializer.
572+
* An augmenting initializer uses `augmented` and the augmented variable is not
573+
a variable with an initializer.
573574

574575
* A final variable is augmented with a setter. (Instead, the augmentation
575576
library can declare a *non-augmenting* setter that goes alongside the
@@ -652,7 +653,7 @@ body. If the augmenting constructor has any initializers, they are appended to
652653
the original constructor's initializers, but before any original super
653654
initializer or original redirecting initializer if there is one.
654655

655-
In the augmenting constructor's body, an `augment super()` call invokes the
656+
In the augmenting constructor's body, an `augmented()` call invokes the
656657
original constructor's body.
657658

658659
It is a compile-time error if:
@@ -685,9 +686,9 @@ It is a compile-time error if:
685686

686687
When augmenting an `external` member, it is assumed that a real implementation
687688
of that member has already been filled by some tool prior to any augmentations
688-
being applied. Thus, it is allowed to use `augment super` from augmenting
689-
members on external declarations, but it may throw a `noSuchMethod` error at
690-
runtime if no implementation was in fact provided.
689+
being applied. Thus, it is allowed to use `augmented` from augmenting members
690+
on external declarations, but it may throw a `noSuchMethod` error at runtime if
691+
no implementation was in fact provided.
691692

692693
**NOTE**: Macros should _not_ be able to statically tell if an external body has
693694
been filled in by a compiler, because it could lead to a different result on
@@ -874,7 +875,7 @@ declaration ::= 'external' factoryConstructorSignature
874875
| 'augment'? constructorSignature (redirection | initializers)?
875876
```
876877

877-
**TODO: Define the grammar for the various `augment super` expressions.**
878+
**TODO: Define the grammar for the various `augmented` expressions.**
878879

879880
It is a compile-time error if:
880881

@@ -951,8 +952,8 @@ To merge a set of declarations `D` into a namespace:
951952

952953
1. Replace a matching variable, getter, and/or setter in the namespace
953954
with the declaration. Inside the augmenting variable's initializer
954-
expression, an `augment super` expression invokes the original
955-
variable initializer.
955+
expression, an `augmented` expression invokes the original variable
956+
initializer.
956957

957958
## Documentation comments
958959

@@ -979,6 +980,10 @@ language and our tools.
979980

980981
## Changelog
981982

983+
## 1.14
984+
985+
* Change `augment super` to `augmented`.
986+
982987
## 1.13
983988

984989
* Clarify which clauses are (not) allowed in augmentations of certain

0 commit comments

Comments
 (0)