Skip to content

Commit 4ac903e

Browse files
committed
Adjust the rules about augmenting constructors wrt default values
1 parent f83e71e commit 4ac903e

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
@@ -734,35 +734,38 @@ provide default values for optional parameters:
734734
class C {
735735
void m1([int i]);
736736
void m2({String name});
737+
void m3({String otherName = "Smith"}); // OK, too.
737738
}
738739
739740
augment class C {
740741
augment m1([i = 1]) {}
741-
augment m2({name = "Smith"}) {}
742+
augment m2({name = "John"}) {}
743+
augment m3({otherName}) {}
742744
}
743745
```
744746

745747
An optional formal parameter has the default value _d_ if exactly one
746748
declaration of that formal parameter in the augmentation chain specifies a
747749
default value, and it is _d_. An optional formal parameter does not have an
748750
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.
752755

753756
It's a **compile-time** error if:
754757

755758
* The signature of the augmenting function does not [match][signature
756759
matching] the signature of the augmented function.
757760

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.*
762765

763766
* 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.
766769

767770
* A function is not complete after all augmentations are applied, unless it
768771
is in a context where it can be abstract. *Every function declaration
@@ -879,11 +882,17 @@ It's a **compile-time error** if:
879882
* The signature of the augmenting function does not [match][signature
880883
matching] the signature of the augmented function.
881884

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.
887896

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

0 commit comments

Comments
 (0)