@@ -734,35 +734,38 @@ provide default values for optional parameters:
734
734
class C {
735
735
void m1([int i]);
736
736
void m2({String name});
737
+ void m3({String otherName = "Smith"}); // OK, too.
737
738
}
738
739
739
740
augment class C {
740
741
augment m1([i = 1]) {}
741
- augment m2({name = "Smith"}) {}
742
+ augment m2({name = "John"}) {}
743
+ augment m3({otherName}) {}
742
744
}
743
745
```
744
746
745
747
An optional formal parameter has the default value _ d_ if exactly one
746
748
declaration of that formal parameter in the augmentation chain specifies a
747
749
default value, and it is _ d_ . An optional formal parameter does not have an
748
750
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.
751
+ augmentation chain specifies a default value; in this case, the default value
752
+ is introduced implicitly with the value null in the case where the parameter
753
+ has a nullable declared type, and no default values for that parameter are
754
+ specified in the augmentation chain.
752
755
753
756
It's a ** compile-time** error if:
754
757
755
758
* The signature of the augmenting function does not [ match] [ signature
756
759
matching] the signature of the augmented function.
757
760
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.*
761
+ * The augmentation chain has two or more specifications of a default value
762
+ for the same optional parameter. This is an error even in the case where
763
+ all of them are identical. * Default values are defined by the introductory
764
+ function or an augmentation, but at most once.*
762
765
763
766
* 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. *
767
+ optional parameter whose declared type is potentially non-nullable, and
768
+ the declared function is not abstract.
766
769
767
770
* A function is not complete after all augmentations are applied, unless it
768
771
is in a context where it can be abstract. * Every function declaration
@@ -879,11 +882,17 @@ It's a **compile-time error** if:
879
882
* The signature of the augmenting function does not [ match] [ signature
880
883
matching] the signature of the augmented function.
881
884
882
- * The augmenting constructor parameters specify any default values, and
883
- the constructor is not a non-redirecting factory. * Default values are
884
- defined by the introductory constructor, except when this precludes the
885
- augmentation from choosing whether or not the constructor should be
886
- redirecting.*
885
+ * The augmentation chain has two or more specifications of a default value
886
+ for the same optional parameter. This is an error even in the case where
887
+ all of them are identical. * Default values are defined by the introductory
888
+ declaration or an augmentation, but at most once.*
889
+
890
+ * The augmentation chain has exactly one specification of a default value
891
+ for an optional parameter, and the constructor is a redirecting factory.
892
+
893
+ * The augmentation chain has no specifications of a default value for an
894
+ optional parameter whose declared type is potentially non-nullable, and
895
+ the constructor is not a redirecting factory.
887
896
888
897
* The introductory constructor is ` const ` and the augmenting constructor
889
898
is not or vice versa. * An augmentation can't change whether or not a
0 commit comments