Skip to content

Commit 9e8895b

Browse files
authored
specify some semantics around augmenting external members (#3086)
Closes #3041 This reverses the previous behavior for `external`, so that `augment super` is always allowed but may throw at runtime.
1 parent 4119e41 commit 9e8895b

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

working/augmentation-libraries/feature-specification.md

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

33
4-
Version: 1.10 (see [Changelog](#Changelog) at end)
4+
Version: 1.11 (see [Changelog](#Changelog) at end)
55

66
Augmentation libraries allow splitting a Dart library into files. Unlike part
77
files, each augmentation has its [own imports][part imports] and top-level
@@ -266,6 +266,10 @@ syntactically mark a declaration as an augmentation of an existing one. The
266266
introduction of this new identifier will be language versioned in order to make
267267
it non-breaking for old code.
268268
269+
It is also allowed for a non-abstract class to have abstract members, if those
270+
members are filled in by an augmentation. This is primarily useful for macros,
271+
which may be used to provide a body for an abstract member.
272+
269273
Often, an augmentation wants to also preserve and run the code of the original
270274
declaration it augments (hence the name "augmentation"). It may want run before
271275
the original code, after it, or both. To allow that, we allow a new expression
@@ -432,13 +436,6 @@ It is a compile-time error if:
432436
* The function augmentation specifies any default values. *Default values are
433437
defined solely by the original function.*
434438

435-
* The original function is declared `external` and the augmenting function
436-
uses `augment super()`.
437-
438-
**TODO: Instead of making this an error, should we add a syntax that lets
439-
the augmentation dynamically detect whether there is an original body to
440-
wrap?**
441-
442439
**TODO: Should we allow augmenting functions to add parameters? If so, how does
443440
this interact with type checking calls to the function?**
444441

@@ -518,15 +515,10 @@ More specifically:
518515
necessary to ensure that macros running after signatures are known can't
519516
change the signature of a declaration.*
520517

521-
**TODO: What if the augmenting variable doesn't have an initializer?**
522-
523518
It is a compile-time error if:
524519

525520
* The original and augmenting declarations do not have the same type.
526521

527-
* An augmenting declaration uses `augment super` when the original declaration
528-
is marked `external`.
529-
530522
* An augmenting initializer uses `augment super` and the original declaration
531523
is not a variable with an initializer.
532524

@@ -638,6 +630,21 @@ It is a compile-time error if:
638630

639631
**TODO: What about redirecting constructors?**
640632

633+
### Augmenting external members
634+
635+
When augmenting an `external` member, it is assumed that a real implementation
636+
of that member has already been filled by some tool prior to any augmentations
637+
being applied. Thus, it is allowed to use `augment super` from augmenting
638+
members on external declarations, but it may throw a `noSuchMethod` error at
639+
runtime if no implementation was in fact provided.
640+
641+
**NOTE**: Macros should _not_ be able to statically tell if an external body has
642+
been filled in by a compiler, because it could lead to a different result on
643+
different platforms or tools.
644+
645+
**TODO: Should we add a syntax to let the augmentation dynamically detect
646+
whether there is an external implementation to call?**
647+
641648
### Metadata annotations and macro applications
642649

643650
An augmentation declaration may have metadata annotations or macro applications.
@@ -921,6 +928,12 @@ language and our tools.
921928

922929
## Changelog
923930

931+
## 1.11
932+
933+
* Alter and clarify the semantics around augmenting external declarations.
934+
* Allow non-abstract classes to have implictly abstract members which are
935+
implemented in an augmentation.
936+
924937
## 1.10
925938

926939
* Make `augment` a built-in identifier.

0 commit comments

Comments
 (0)