Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -575,64 +575,81 @@ constructors as well.
```ebnf
<classDeclaration> ::= // First alternative modified.
(<classModifiers> | <mixinClassModifiers>)
'class' <classNamePart> <superclass>? <interfaces>? <classBody>
'class' <classNameMaybePrimary> <superclass>? <interfaces>? <classBody>
| ...;

<primaryConstructorNoConst> ::= // New rule.
<typeIdentifier> <typeParameters>?
('.' <identifierOrNew>)? <declaringParameterList>
<primaryConstructor> ::= // New rule.
'const'? <typeWithParameters> ('.' <identifierOrNew>)?
<declaringParameterList>;

<classNamePart> ::= // New rule.
'const'? <primaryConstructorNoConst>
<classNameMaybePrimary> ::= // New rule.
<primaryConstructor>
| <typeWithParameters>;

<typeWithParameters> ::= <typeIdentifier> <typeParameters>?

<classBody> ::= // New rule.
'{' (<metadata> <classMemberDeclaration>)* '}'
'{' (<metadata> <memberDeclaration>)* '}'
| ';';

<extensionTypeDeclaration> ::= // Modified rule.
'extension' 'type' <classNamePart> <interfaces>?
'extension' 'type' <classNameMaybePrimary> <interfaces>?
<extensionTypeBody>;

<extensionTypeMemberDeclaration> ::= <classMemberDeclaration>;

<extensionTypeBody> ::=
'{' (<metadata> <extensionTypeMemberDeclaration>)* '}'
'{' (<metadata> <memberDeclaration>)* '}'
| ';';

<enumType> ::= // Modified rule.
'enum' <classNamePart> <mixins>? <interfaces>? '{'
<enumEntry> (',' <enumEntry>)* (',')?
(';' (<metadata> <classMemberDeclaration>)*)?
'enum' <classNameMaybePrimary> <mixins>? <interfaces>? '{'
<enumEntry> (',' <enumEntry>)* ','?
(';' (<metadata> <memberDeclaration>)*)?
'}';

<constructorSignature> ::= // Modified rule.
<constructorName> <formalParameterList>
<constructorName> <formalParameterList> // Old form.
| <constructorHead> <formalParameterList> // New form.
| <declaringConstructorSignature>;

<declaringConstructorSignature> ::= // New rule.
'this' ('.' <identifierOrNew>)? <declaringParameterList>?;
'this' <identifier>? <declaringParameterList>?;

<constantConstructorSignature> ::= // Modified rule.
'const' <constructorName> <formalParameterList>
'const' <constructorName> <formalParameterList> // Old form.
| 'const' <constructorHead> <formalParameterList> // New form.
| <declaringConstantConstructorSignature>;

<constructorName> ::= // Modified rule.
<typeIdentifierOrNew> ('.' identifierOrNew)?;

<typeIdentifierOrNew> ::= // New rule.
<typeIdentifier>
| 'new';
<typeIdentifier> ('.' identifierOrNew)?;

<declaringConstantConstructorSignature> ::= // New rule.
'const' 'this' ('.' <identifierOrNew>)? <declaringParameterList>;
'const' 'this' <identifier>? <declaringParameterList>;

<constructorHead> ::= // New rule.
'new' <identifier>?;

<factoryConstructorHead> ::= // New rule.
'factory' <identifier>?;

<identifierOrNew> ::=
<identifier>
| 'new'

<factoryConstructorSignature> ::= // Modified rule.
'const'? 'factory' <constructorName> <formalParameterList> // Old form.
| 'const'? <factoryConstructorHead> <formalParameterList>; // New form.

<redirectingFactoryConstructorSignature> ::= // Modified rule.
'const'? 'factory' <constructorName> <formalParameterList> '='
<constructorDesignation> // Old form.
| 'CONST'? <factoryConstructorHead> <formalParameterList> '='
<constructorDesignation>; // New form.

<constantConstructorSignature> ::= // Modified rule.
: 'const' <constructorName> <formalParameterList> // Old form.
| 'const' <constructorHead> <formalParameterList> // New form.
| <declaringConstantConstructorSignature>;

<simpleFormalParameter> ::= // Modified rule.
'covariant'? <type>? <identifier>;

Expand Down Expand Up @@ -685,31 +702,39 @@ constructors as well.
('=' <expression>)?;
```

The word `factory` is removed from the set of built-in identifiers and
added to the set of reserved words.

*This allows the new constructor declaration syntax such as `factory();` to
be unambiguous. It is also a breaking change because `factory` can no
longer be the name of a declaration. However, this occurs only infrequently
today.*

A _declaring constructor_ declaration is a declaration that contains a
`<declaringConstructorSignature>` with a `<declaringParameterList>`, or a
declaration that contains a `<declaringConstantConstructorSignature>`, or
it is a `<primaryConstructorNoConst>` in the header of a class, enum, or
extension type declaration, together with a declaration in the body that
contains a `<declaringConstructorSignature>` *(which does not contain a
it is a `<primaryConstructor>` in the header of a class, enum, or extension
type declaration, together with a declaration in the body that contains a
`<declaringConstructorSignature>` *(which does not contain a
`<declaringParameterList>`, because that's an error)*.

A class or extension type declaration whose class body is `;` is treated as
a declaration whose body is `{}`.

Let _D_ be a class, extension type, or enum declaration.

A compile-time error occurs if _D_ includes a `<classNamePart>` that
contains a `<primaryConstructorNoConst>`, and the body of _D_ contains a
A compile-time error occurs if _D_ includes a `<classNameMaybePrimary>`
that contains a `<primaryConstructor>`, and the body of _D_ contains a
`<declaringConstructorSignature>` that contains a
`<declaringParameterList>`.

*It is an error to have a declaring parameter list both in the header and
in the body.*

A compile-time error occurs if _D_ includes a `<classNamePart>` that
does not contain a `<primaryConstructorNoConst>`, and the body of _D_
contains a `<declaringConstructorSignature>` that does not
contain a `<declaringParameterList>`.
A compile-time error occurs if _D_ includes a `<classNameMaybePrimary>`
that does not contain a `<primaryConstructor>`, and the body of _D_
contains a `<declaringConstructorSignature>` that does not contain a
`<declaringParameterList>`.

*It is an error to have a declaring constructor in the class body, but
no declaring parameter list, neither in the header nor in the body.*
Expand Down