@@ -419,7 +419,7 @@ scope. *We could say that it attaches itself to the existing name.*
419
419
420
420
Augmentations aren't allowed to * replace* code, so they mostly add entirely new
421
421
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.
423
423
424
424
More precisely, a function or constructor declaration (introductory or
425
425
augmenting) is * incomplete* if all of:
@@ -727,14 +727,42 @@ augment class Person {
727
727
}
728
728
```
729
729
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
+
730
753
It's a ** compile-time** error if:
731
754
732
755
* The signature of the augmenting function does not [ match] [ signature
733
756
matching] the signature of the augmented function.
734
757
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.*
738
766
739
767
* A function is not complete after all augmentations are applied, unless it
740
768
is in a context where it can be abstract. * Every function declaration
0 commit comments