Skip to content

Commit 0538595

Browse files
authored
Add clarifying section on the semantics of super augment in various augmenting contexts (#3045)
Closes #2325 Closes #2324
1 parent 8a9315e commit 0538595

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

working/augmentation-libraries/feature-specification.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ declaration it augments (hence the name "augmentation"). It may want run before
269269
the original code, after it, or both. To allow that, we allow a new expression
270270
syntax inside the bodies of augmenting members. Inside a member marked
271271
`augment`, an expression like `augment super` can be used to refer to the
272-
original function, getter, setter, or variable initializer.
272+
original function, getter, setter, or variable initializer. See the next
273+
section for a full specification of what `augment super` actually means,
274+
in the various contexts.
273275
274276
**TODO: I'm not sold on `augment super`. Is there a better syntax?**
275277
@@ -286,6 +288,43 @@ It is a compile-time error if:
286288
original declaration occurs, according to merge order. *An augmentation
287289
library can both declare a new declaration and augment it in the same file.*
288290
291+
### Augment super
292+
293+
The exact result of an `augment super` expression depends on what is being
294+
augmented, but it follows generally the same rules as any normal identifier:
295+
296+
* **Augmenting getters**: Within an augmenting getter `augment super` invokes
297+
the getter and evaluates to the return value. If augmenting a field with a
298+
getter, this will invoke the implicit getter from the augmented field.
299+
300+
* **Augmenting setters**: Within an augmenting setter `augment super` must be
301+
followed by an `=` and will directly invoke the augmented setter. If
302+
augmenting a field with a setter, this will invoke the implicit setter from
303+
the augmented field.
304+
305+
* **Augmenting fields**: Within an augmenting field, `augment super` can only
306+
be used in an initializer expression, and refers to the original field's
307+
initializer expression, which is immediately evaluated.
308+
309+
It is a compile-time error to use `augment super` in an augmenting field's
310+
initializer if the member being augmented is not a field with an
311+
initializer.
312+
313+
**TODO:** Define the behavior when a field is augmented by a getter or
314+
setter, and then later again by a field.
315+
316+
* **Augmenting functions**: When augmenting a function, `augment super` refers
317+
to the augmented function. Tear offs are allowed.
318+
319+
* **Augmenting operators**: When augmenting an operator, `augment super` must
320+
be followed by the operator. For example when augmenting `+` you must do
321+
`augment super + 1`, and when augmenting `[]` you must do
322+
`augment super[<arg>]`. These constructs invoke the augmented operator, and
323+
are the only valid uses of `augment super` in these contexts.
324+
325+
* **Augmenting enum values**: When augmenting an enum value, `augment super`
326+
has no meaning and is not allowed.
327+
289328
### Augmenting types
290329
291330
A class, mixin, enum, or extension declaration can be marked with an `augment`

0 commit comments

Comments
 (0)