|
1 | 1 | # Augmentations
|
2 | 2 |
|
3 | 3 |
|
4 |
| -Version: 1.32 (see [Changelog](#Changelog) at end) |
| 4 | +Version: 1.33 (see [Changelog](#Changelog) at end) |
5 | 5 |
|
6 | 6 | Augmentations allow spreading your implementation across multiple locations,
|
7 | 7 | both within a single file and across multiple files. They can add new top-level
|
@@ -950,17 +950,12 @@ representation field, and an empty body. The representation field clause must
|
950 | 950 | be present on the declaration which introduces the extension type, and must be
|
951 | 951 | omitted from all augmentations of the extension type.
|
952 | 952 |
|
953 |
| -**TODO**: Update the grammar to allow extension types to omit the parenthesized |
954 |
| -clause with the representation type (or possibly only augmentations of extension |
955 |
| -types, but it is probably better to make this a semantic error and not a |
956 |
| -syntactic one to provide a better dev experience). |
957 |
| - |
958 | 953 | This means that an augmentation can add a body to an extension type's implicit
|
959 | 954 | constructor, which isn't otherwise possible. This is done by augmenting the
|
960 |
| -constructor in the body of the extension type *(But note that there is no |
| 955 | +constructor in the body of the extension type. *Note that there is no |
961 | 956 | guarantee that any instance of an extension type will have necessarily executed
|
962 | 957 | that body, since you can get instances of extension types through casts or other
|
963 |
| -conversions that sidestep the constructor.)*. For example: |
| 958 | +conversions that sidestep the constructor.* For example: |
964 | 959 |
|
965 | 960 | ```dart
|
966 | 961 | extension type A(int b) {
|
@@ -1139,35 +1134,39 @@ topLevelDeclaration ::= classDeclaration
|
1139 | 1134 |
|
1140 | 1135 | classDeclaration ::= 'augment'? (classModifiers | mixinClassModifiers)
|
1141 | 1136 | 'class' typeWithParameters superclass? interfaces?
|
1142 |
| - '{' (metadata classMemberDeclaration)* '}' |
| 1137 | + memberedDeclarationBody |
1143 | 1138 | | 'augment'? classModifiers 'mixin'? 'class' mixinApplicationClass
|
1144 | 1139 |
|
1145 | 1140 | mixinDeclaration ::= 'augment'? 'base'? 'mixin' typeIdentifier
|
1146 | 1141 | typeParameters? ('on' typeNotVoidNotFunctionList)? interfaces?
|
1147 |
| - '{' (metadata mixinMemberDeclaration)* '}' |
| 1142 | + memberedDeclarationBody |
1148 | 1143 |
|
1149 | 1144 | extensionDeclaration ::=
|
1150 | 1145 | 'extension' typeIdentifierNotType? typeParameters? 'on' type
|
1151 |
| - extensionBody |
| 1146 | + memberedDeclarationBody |
1152 | 1147 | | 'augment' 'extension' typeIdentifierNotType typeParameters?
|
1153 |
| - extensionBody |
1154 |
| -
|
1155 |
| -extensionBody ::= '{' (metadata classMemberDeclaration)* '}' |
| 1148 | + memberedDeclarationBody |
1156 | 1149 |
|
1157 | 1150 | extensionTypeDeclaration ::=
|
1158 |
| - 'augment'? 'extension' 'type' 'const'? typeIdentifier |
1159 |
| - typeParameters? representationDeclaration interfaces? |
1160 |
| - '{' (metadata classMemberDeclaration)* '}' |
| 1151 | + 'extension' 'type' 'const'? typeIdentifier |
| 1152 | + typeParameters? representationDeclaration interfaces? |
| 1153 | + memberedDeclarationBody |
| 1154 | + | 'augment' 'extension' 'type' typeIdentifier typeParameters? interfaces? |
| 1155 | + memberedDeclarationBody |
1161 | 1156 |
|
1162 | 1157 | enumType ::= 'augment'? 'enum' typeIdentifier
|
1163 | 1158 | typeParameters? mixins? interfaces?
|
1164 | 1159 | '{' enumEntry (',' enumEntry)* (',')?
|
1165 |
| - (';' (metadata classMemberDeclaration)*)? '}' |
| 1160 | + (';' memberDeclarations)? '}' |
1166 | 1161 |
|
1167 | 1162 | typeAlias ::= 'augment'? 'typedef' typeIdentifier typeParameters? '=' type ';'
|
1168 | 1163 | | 'augment'? 'typedef' functionTypeAlias
|
1169 | 1164 |
|
1170 |
| -classMemberDeclaration ::= declaration ';' |
| 1165 | +memberedDeclarationBody ::= '{' memberDeclarations '}' |
| 1166 | +
|
| 1167 | +memberDeclarations ::= (metadata memberDeclaration)* |
| 1168 | +
|
| 1169 | +memberDeclaration ::= declaration ';' |
1171 | 1170 | | 'augment'? methodSignature functionBody
|
1172 | 1171 |
|
1173 | 1172 | enumEntry ::= metadata 'augment'? identifier argumentPart?
|
@@ -1400,6 +1399,11 @@ to the augmentation.
|
1400 | 1399 |
|
1401 | 1400 | ## Changelog
|
1402 | 1401 |
|
| 1402 | +### 1.33 |
| 1403 | + |
| 1404 | +* Change the grammar to remove the primary constructor parts of an |
| 1405 | + augmenting extension type declaration. |
| 1406 | + |
1403 | 1407 | ### 1.32
|
1404 | 1408 |
|
1405 | 1409 | * Specify that variables which require an initializer can have it defined
|
|
0 commit comments