Skip to content

Commit 4e583e5

Browse files
authored
Change the syntax of augmenting extension type declarations (#4016)
Change the grammar such that an augmenting extension type declaration does not specify a primary constructor.
1 parent f5153f7 commit 4e583e5

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

working/augmentation-libraries/feature-specification.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Augmentations
22

33
4-
Version: 1.32 (see [Changelog](#Changelog) at end)
4+
Version: 1.33 (see [Changelog](#Changelog) at end)
55

66
Augmentations allow spreading your implementation across multiple locations,
77
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
950950
be present on the declaration which introduces the extension type, and must be
951951
omitted from all augmentations of the extension type.
952952

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-
958953
This means that an augmentation can add a body to an extension type's implicit
959954
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
961956
guarantee that any instance of an extension type will have necessarily executed
962957
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:
964959

965960
```dart
966961
extension type A(int b) {
@@ -1139,35 +1134,39 @@ topLevelDeclaration ::= classDeclaration
11391134
11401135
classDeclaration ::= 'augment'? (classModifiers | mixinClassModifiers)
11411136
'class' typeWithParameters superclass? interfaces?
1142-
'{' (metadata classMemberDeclaration)* '}'
1137+
memberedDeclarationBody
11431138
| 'augment'? classModifiers 'mixin'? 'class' mixinApplicationClass
11441139
11451140
mixinDeclaration ::= 'augment'? 'base'? 'mixin' typeIdentifier
11461141
typeParameters? ('on' typeNotVoidNotFunctionList)? interfaces?
1147-
'{' (metadata mixinMemberDeclaration)* '}'
1142+
memberedDeclarationBody
11481143
11491144
extensionDeclaration ::=
11501145
'extension' typeIdentifierNotType? typeParameters? 'on' type
1151-
extensionBody
1146+
memberedDeclarationBody
11521147
| 'augment' 'extension' typeIdentifierNotType typeParameters?
1153-
extensionBody
1154-
1155-
extensionBody ::= '{' (metadata classMemberDeclaration)* '}'
1148+
memberedDeclarationBody
11561149
11571150
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
11611156
11621157
enumType ::= 'augment'? 'enum' typeIdentifier
11631158
typeParameters? mixins? interfaces?
11641159
'{' enumEntry (',' enumEntry)* (',')?
1165-
(';' (metadata classMemberDeclaration)*)? '}'
1160+
(';' memberDeclarations)? '}'
11661161
11671162
typeAlias ::= 'augment'? 'typedef' typeIdentifier typeParameters? '=' type ';'
11681163
| 'augment'? 'typedef' functionTypeAlias
11691164
1170-
classMemberDeclaration ::= declaration ';'
1165+
memberedDeclarationBody ::= '{' memberDeclarations '}'
1166+
1167+
memberDeclarations ::= (metadata memberDeclaration)*
1168+
1169+
memberDeclaration ::= declaration ';'
11711170
| 'augment'? methodSignature functionBody
11721171
11731172
enumEntry ::= metadata 'augment'? identifier argumentPart?
@@ -1400,6 +1399,11 @@ to the augmentation.
14001399

14011400
## Changelog
14021401

1402+
### 1.33
1403+
1404+
* Change the grammar to remove the primary constructor parts of an
1405+
augmenting extension type declaration.
1406+
14031407
### 1.32
14041408

14051409
* Specify that variables which require an initializer can have it defined

0 commit comments

Comments
 (0)