Skip to content

Commit 0b19eff

Browse files
committed
[augmentations] Clarify a few corners.
* Specify that augmenting constructor initializers are inserted before the original constructor's super or redirecting initializer if present. * Specify that an augmenting type must replicate the original type's type parameters. * Allow augmenting declarations to add metadata annotations and macro applications. Fix #2062. Fix #2058. Fix #2061.
1 parent 91fee34 commit 0b19eff

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

working/augmentation-libraries/feature-specification.md

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Augmentation Libraries
22

3-
Author: [email protected], Version: 1.1 (see Changelog at end)
3+
Author: [email protected], Version: 1.2 (see [Changelog](#Changelog) at end)
44

55
Augmentation libraries allow splitting a Dart library into files. Unlike part
66
files, each augmentation has its [own imports][part imports] and top-level
@@ -247,11 +247,20 @@ declaration according to the rules in the following subsections.
247247

248248
It is a compile-time error if:
249249

250+
* The type parameters of the type augmentation do not exactly match the
251+
original type's type parameters. This means there must be the same number of
252+
type parameters with the same names and same bounds.
253+
254+
*Since repeating the type parameters is, by definition, redundant, this
255+
doesn't accomplish anything semantically. But it ensures that anyone reading
256+
the augmenting type can see the declarations of any type parameters that it
257+
uses in its body.*
258+
250259
* The augmenting type and corresponding type are not the same kind: class,
251260
mixin, extension. You can't augment a class with a mixin, etc.
252261

253-
* The augmenting type declares any type parameters or an `extends` clause.
254-
Only the main declaration can specify those.
262+
* The augmenting type declares an `extends` clause. Only the main declaration
263+
can specify those.
255264

256265
**TODO: We could consider allowing an `extends` clause if the main
257266
declaration doesn't have one.**
@@ -295,6 +304,11 @@ It is a compile-time error if:
295304
and bounds must be the same; and any `required` or `covariant` modifiers
296305
must match.
297306

307+
*Since repeating the signature is, by definition, redundant, this doesn't
308+
accomplish anything semantically. But it ensures that anyone reading the
309+
augmenting function can see the declarations of any parameters that it
310+
uses in its body.*
311+
298312
* The original function is declared `external` and the augmenting function
299313
uses `augment super()`.
300314

@@ -396,18 +410,23 @@ It is a compile-time error if:
396410

397411
Constructors are (as always) more complex. A constructor marked `augment`
398412
replaces the body of the corresponding constructor in the main library with its
399-
body. It appends its initializer list to the original constructor's. In the
400-
augmenting constructor's body, an `augment super()` call invokes the original
401-
constructor's body.
413+
body. If the augmenting constructor has any initializers, they are appended to
414+
the original constructor's initializers, but before any original super
415+
initializer or original redirecting initializer if there is one.
416+
417+
In the augmenting constructor's body, an `augment super()` call invokes the
418+
original constructor's body.
402419

403420
It is a compile-time error if:
404421

405422
* The signature of the constructor augmentation does not exactly match the
406-
original constructor. This means there must be the same number of
407-
positional, optional, and named parameters; the types of corresponding
408-
positional and optional parameters must be the same; and the names and types
409-
of named parameters must be the same. Any initializing formals must be the
410-
same in both constructors.
423+
original constructor. This means the return types must be the same; there
424+
must be the same number of positional, optional, and named parameters; the
425+
types of corresponding positional and optional parameters must be the same;
426+
the names and types of named parameters must be the same; any type
427+
parameters and bounds must be the same; and any `required` or `covariant`
428+
modifiers must match. Any initializing formals must be the same in both
429+
constructors.
411430

412431
**TODO: Is this the right way to handle initializing formals?**
413432

@@ -417,8 +436,17 @@ It is a compile-time error if:
417436
* The original constructor is a factory constructor and the augmenting
418437
constructor has an initializer list.
419438

439+
* The original constructor has a super initializer or redirecting initializer
440+
and the augmenting constructor does too.
441+
420442
**TODO: What about redirecting constructors?**
421443

444+
### Metadata annotations and macro applications
445+
446+
An augmentation declaration may have metadata annotations or macros
447+
applications. These are appended to the list of metadata annotations and macro
448+
applications on the original declaration.
449+
422450
## Scoping
423451

424452
Unlike part files, an augmentation library has its own top-level lexical scope
@@ -680,6 +708,15 @@ tools.
680708

681709
## Changelog
682710

711+
### 1.2
712+
713+
* Specify that augmenting constructor initializers are inserted before the
714+
original constructor's super or redirecting initializer if present (#2062).
715+
* Specify that an augmenting type must replicate the original type's type
716+
parameters (#2058).
717+
* Allow augmenting declarations to add metadata annotations and macro
718+
applications (#2061).
719+
683720
### 1.1
684721

685722
* Make it an error to apply the same augmentation multiple times (#1957).

0 commit comments

Comments
 (0)