Skip to content

Commit 0aa6add

Browse files
committed
Adjust the rules about augmenting constructors wrt default values
1 parent fb0ed11 commit 0aa6add

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

working/augmentation-libraries/feature-specification.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -775,35 +775,38 @@ provide default values for optional parameters:
775775
class C {
776776
void m1([int i]);
777777
void m2({String name});
778+
void m3({String otherName = "Smith"}); // OK, too.
778779
}
779780
780781
augment class C {
781782
augment m1([i = 1]) {}
782-
augment m2({name = "Smith"}) {}
783+
augment m2({name = "John"}) {}
784+
augment m3({otherName}) {}
783785
}
784786
```
785787

786788
An optional formal parameter has the default value _d_ if exactly one
787789
declaration of that formal parameter in the augmentation chain specifies a
788790
default value, and it is _d_. An optional formal parameter does not have an
789791
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.
792+
augmentation chain specifies a default value; in this case, the default value
793+
is introduced implicitly with the value null in the case where the parameter
794+
has a nullable declared type, and no default values for that parameter are
795+
specified in the augmentation chain.
793796

794797
It's a **compile-time** error if:
795798

796799
* The signature of the augmenting function does not [match][signature
797800
matching] the signature of the augmented function.
798801

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.*
802+
* The augmentation chain has two or more specifications of a default value
803+
for the same optional parameter. This is an error even in the case where
804+
all of them are identical. *Default values are defined by the introductory
805+
function or an augmentation, but at most once.*
803806

804807
* 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.*
808+
optional parameter whose declared type is potentially non-nullable, and
809+
the declared function is not abstract.
807810

808811
* A function is not complete after all augmentations are applied, unless it's
809812
an instance member and the surrounding class is abstract. *Every function
@@ -884,11 +887,17 @@ It's a **compile-time error** if:
884887
* The signature of the augmenting function does not [match][signature
885888
matching] the signature of the augmented function.
886889

887-
* The augmenting constructor parameters specify any default values, and
888-
the constructor is not a non-redirecting factory. *Default values are
889-
defined by the introductory constructor, except when this precludes the
890-
augmentation from choosing whether or not the constructor should be
891-
redirecting.*
890+
* The augmentation chain has two or more specifications of a default value
891+
for the same optional parameter. This is an error even in the case where
892+
all of them are identical. *Default values are defined by the introductory
893+
declaration or an augmentation, but at most once.*
894+
895+
* The augmentation chain has exactly one specification of a default value
896+
for an optional parameter, and the constructor is a redirecting factory.
897+
898+
* The augmentation chain has no specifications of a default value for an
899+
optional parameter whose declared type is potentially non-nullable, and
900+
the constructor is not a redirecting factory.
892901

893902
* The introductory constructor is `const` and the augmenting constructor
894903
is not or vice versa. *An augmentation can't change whether or not a

0 commit comments

Comments
 (0)