Skip to content

Commit bd43d37

Browse files
committed
Indroduce changes from pre-move version of the feature specification of augmentations
1 parent f9c9aa3 commit bd43d37

File tree

1 file changed

+57
-7
lines changed

1 file changed

+57
-7
lines changed

working/augmentations/feature-specification.md

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
44

5-
Version: 1.37 (see [Changelog](#Changelog) at end)
5+
Version: 1.38 (see [Changelog](#Changelog) at end)
66

77
Experiment flag: augmentations
88

@@ -453,7 +453,7 @@ scope. *We could say that it attaches itself to the existing name.*
453453

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

458458
More precisely, a function or constructor declaration (introductory or
459459
augmenting) is *incomplete* if all of:
@@ -771,13 +771,45 @@ augment class Person {
771771
}
772772
```
773773

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

776802
* The signature of the augmenting function does not [match][signature
777803
matching] the signature of the augmented function.
778804

779-
* The augmenting function specifies any default values. *Default values are
780-
defined solely by the introductory function.*
805+
* The augmentation chain has two or more specifications of a default value
806+
for the same optional parameter. This is an error even in the case where
807+
all of them are identical. *Default values are defined by the introductory
808+
function or an augmentation, but at most once.*
809+
810+
* The augmentation chain has no specifications of a default value for an
811+
optional parameter whose declared type is potentially non-nullable, and
812+
the declared function is not abstract.
781813

782814
* A function is not complete after all augmentations are applied, unless it's
783815
an instance member and the surrounding class is abstract. *Every function
@@ -848,16 +880,30 @@ Augmenting constructors works similar to augmenting a function, with some extra
848880
rules to handle features unique to constructors like redirections and
849881
initializer lists.
850882

883+
It is **not** a compile-time error for an incomplete factory constructor to
884+
omit default values. *That is, they are treated similarly to abstract
885+
instance methods in this respect. This allows the augmenting declaration to
886+
implement the constructor by adding a redirection or a body.*
887+
851888
It's a **compile-time error** if:
852889

853890
* The signature of the augmenting function does not [match][signature
854891
matching] the signature of the augmented function.
855892

856-
* The augmenting constructor parameters specify any default values.
857-
*Default values are defined solely by the introductory constructor.*
893+
* The augmentation chain has two or more specifications of a default value
894+
for the same optional parameter. This is an error even in the case where
895+
all of them are identical. *Default values are defined by the introductory
896+
declaration or an augmentation, but at most once.*
897+
898+
* The augmentation chain has exactly one specification of a default value
899+
for an optional parameter, and the constructor is a redirecting factory.
900+
901+
* The augmentation chain has no specifications of a default value for an
902+
optional parameter whose declared type is potentially non-nullable, and
903+
the constructor is not a redirecting factory.
858904

859905
* The introductory constructor is `const` and the augmenting constructor
860-
is not or vice versa. *An augmentation can't change whether or not a
906+
is not, or vice versa. *An augmentation can't change whether or not a
861907
constructor is const because that affects whether users are allowed to use
862908
the constructor in a const context.*
863909

@@ -1128,6 +1174,10 @@ and assume the third point is always true.
11281174

11291175
## Changelog
11301176

1177+
### 1.38
1178+
1179+
* Generalize the treatment of default values of optional parameters.
1180+
11311181
### 1.37
11321182

11331183
* Rename to "augmentations" (from "augmentation libraries") and define the

0 commit comments

Comments
 (0)