1
1
# Augmentation Libraries
2
2
3
- Author:
[email protected] , Version: 1.
1 (see Changelog at end)
3
+ Author:
[email protected] , Version: 1.
2 (see
[ Changelog
] ( #Changelog ) at end)
4
4
5
5
Augmentation libraries allow splitting a Dart library into files. Unlike part
6
6
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.
247
247
248
248
It is a compile-time error if:
249
249
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
+
250
259
* The augmenting type and corresponding type are not the same kind: class,
251
260
mixin, extension. You can't augment a class with a mixin, etc.
252
261
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.
255
264
256
265
** TODO: We could consider allowing an ` extends ` clause if the main
257
266
declaration doesn't have one.**
@@ -295,6 +304,11 @@ It is a compile-time error if:
295
304
and bounds must be the same; and any ` required ` or ` covariant ` modifiers
296
305
must match.
297
306
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
+
298
312
* The original function is declared ` external ` and the augmenting function
299
313
uses ` augment super() ` .
300
314
@@ -396,18 +410,23 @@ It is a compile-time error if:
396
410
397
411
Constructors are (as always) more complex. A constructor marked ` augment `
398
412
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.
402
419
403
420
It is a compile-time error if:
404
421
405
422
* 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.
411
430
412
431
** TODO: Is this the right way to handle initializing formals?**
413
432
@@ -417,8 +436,17 @@ It is a compile-time error if:
417
436
* The original constructor is a factory constructor and the augmenting
418
437
constructor has an initializer list.
419
438
439
+ * The original constructor has a super initializer or redirecting initializer
440
+ and the augmenting constructor does too.
441
+
420
442
** TODO: What about redirecting constructors?**
421
443
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
+
422
450
## Scoping
423
451
424
452
Unlike part files, an augmentation library has its own top-level lexical scope
@@ -680,6 +708,15 @@ tools.
680
708
681
709
## Changelog
682
710
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
+
683
720
### 1.1
684
721
685
722
* Make it an error to apply the same augmentation multiple times (#1957 ).
0 commit comments