Skip to content

Commit f83e71e

Browse files
committed
Specify that default values can be specified at most once in an augmentation chain
1 parent fee478f commit f83e71e

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

working/augmentation-libraries/feature-specification.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ scope. *We could say that it attaches itself to the existing name.*
419419

420420
Augmentations aren't allowed to *replace* code, so they mostly add entirely new
421421
declarations to the surrounding type. However, function and constructor
422-
augmentations can fill in a body for an augmented declaration that is lacks one.
422+
augmentations can fill in a body for an augmented declaration that lacks one.
423423

424424
More precisely, a function or constructor declaration (introductory or
425425
augmenting) is *incomplete* if all of:
@@ -727,14 +727,42 @@ augment class Person {
727727
}
728728
```
729729

730+
A top-level function, static method, or instance method may be augmented to
731+
provide default values for optional parameters:
732+
733+
```dart
734+
class C {
735+
void m1([int i]);
736+
void m2({String name});
737+
}
738+
739+
augment class C {
740+
augment m1([i = 1]) {}
741+
augment m2({name = "Smith"}) {}
742+
}
743+
```
744+
745+
An optional formal parameter has the default value _d_ if exactly one
746+
declaration of that formal parameter in the augmentation chain specifies a
747+
default value, and it is _d_. An optional formal parameter does not have an
748+
explicitly specified default value if none of its declarations in the
749+
augmentation chain specifies a default value; the default value is introduced
750+
implicitly with the value null in the case where the parameter has a nullable
751+
declared type, and no default values are specified in the augmentation chain.
752+
730753
It's a **compile-time** error if:
731754

732755
* The signature of the augmenting function does not [match][signature
733756
matching] the signature of the augmented function.
734757

735-
* The augmenting function specifies any default values. *Default values are
736-
defined solely by the introductory function. Note that constructors are
737-
treated differently from other functions in this respect.*
758+
* The augmentation chain has two or more specifications of a default
759+
value, even in the case where they are all identical. *Default values are
760+
defined by the introductory function or an augmentation, but at most
761+
once.*
762+
763+
* The augmentation chain has no specifications of a default value for an
764+
optional parameter whose declared type is potentially non-nullable. *In
765+
this case the specification must be explicit.*
738766

739767
* A function is not complete after all augmentations are applied, unless it
740768
is in a context where it can be abstract. *Every function declaration

0 commit comments

Comments
 (0)