Skip to content

Commit fb0ed11

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

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
@@ -450,7 +450,7 @@ scope. *We could say that it attaches itself to the existing name.*
450450

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

455455
More precisely, a function or constructor declaration (introductory or
456456
augmenting) is *incomplete* if all of:
@@ -768,14 +768,42 @@ augment class Person {
768768
}
769769
```
770770

771+
A top-level function, static method, or instance method may be augmented to
772+
provide default values for optional parameters:
773+
774+
```dart
775+
class C {
776+
void m1([int i]);
777+
void m2({String name});
778+
}
779+
780+
augment class C {
781+
augment m1([i = 1]) {}
782+
augment m2({name = "Smith"}) {}
783+
}
784+
```
785+
786+
An optional formal parameter has the default value _d_ if exactly one
787+
declaration of that formal parameter in the augmentation chain specifies a
788+
default value, and it is _d_. An optional formal parameter does not have an
789+
explicitly specified default value if none of its declarations in the
790+
augmentation chain specifies a default value; the default value is introduced
791+
implicitly with the value null in the case where the parameter has a nullable
792+
declared type, and no default values are specified in the augmentation chain.
793+
771794
It's a **compile-time** error if:
772795

773796
* The signature of the augmenting function does not [match][signature
774797
matching] the signature of the augmented function.
775798

776-
* The augmenting function specifies any default values. *Default values are
777-
defined solely by the introductory function. Note that constructors are
778-
treated differently from other functions in this respect.*
799+
* The augmentation chain has two or more specifications of a default
800+
value, even in the case where they are all identical. *Default values are
801+
defined by the introductory function or an augmentation, but at most
802+
once.*
803+
804+
* The augmentation chain has no specifications of a default value for an
805+
optional parameter whose declared type is potentially non-nullable. *In
806+
this case the specification must be explicit.*
779807

780808
* A function is not complete after all augmentations are applied, unless it's
781809
an instance member and the surrounding class is abstract. *Every function

0 commit comments

Comments
 (0)