@@ -485,16 +485,17 @@ constructors as well.
485485
486486<constructorSignature> ::= // Modified rule.
487487 <constructorName> <formalParameterList> // Old form.
488- | <constructorHead> <formalParameterList> // New form.
489- | 'this';
488+ | <constructorHead> <formalParameterList>; // New form.
490489
491490<constantConstructorSignature> ::= // Modified rule.
492- 'const' <constructorName> <formalParameterList> // Old form.
493- | 'const' <constructorHead> <formalParameterList>; // New form.
491+ 'const' <constructorSignature>;
494492
495493<constructorName> ::= // Modified rule.
496494 <typeIdentifier> ('.' identifierOrNew)?;
497495
496+ <constructorTwoPartName> ::= // New rule.
497+ <typeIdentifier> '.' identifierOrNew;
498+
498499<constructorHead> ::= // New rule.
499500 'new' <identifier>?;
500501
@@ -506,18 +507,24 @@ constructors as well.
506507 | 'new'
507508
508509<factoryConstructorSignature> ::= // Modified rule.
509- 'const'? 'factory' <constructorName> <formalParameterList> // Old form.
510- | 'const'? <factoryConstructorHead> <formalParameterList>; // New form.
510+ 'const'? 'factory' <constructorTwoPartName>
511+ <formalParameterList> // Old form.
512+ | 'const'? <factoryConstructorHead>
513+ <formalParameterList>; // New form.
511514
512515<redirectingFactoryConstructorSignature> ::= // Modified rule.
513- 'const'? 'factory' <constructorName> <formalParameterList> '='
514- <constructorDesignation> // Old form.
515- | 'const'? <factoryConstructorHead> <formalParameterList> '='
516- <constructorDesignation>; // New form.
516+ <factoryConstructorSignature> '=' <constructorDesignation>;
517517
518- <constantConstructorSignature> ::= // Modified rule.
519- : 'const' <constructorName> <formalParameterList> // Old form.
520- | 'const' <constructorHead> <formalParameterList>; // New form.
518+ <primaryConstructorBodySignature> ::= // New rule.
519+ 'this' initializers?;
520+
521+ <methodSignature> ::= // Add one new alternative.
522+ ...
523+ | <primaryConstructorBodySignature>;
524+
525+ <declaration> ::= // Add one new alternative.
526+ ...
527+ | <primaryConstructorBodySignature>;
521528
522529<simpleFormalParameter> ::= // Modified rule.
523530 'covariant'? <type>? <identifier>;
@@ -590,10 +597,14 @@ or one or more of the modifiers `const`, `augment`, or `external` followed
590597by ` factory ` , it proceeds to parse the following input as a factory
591598constructor.
592599
600+ * This is similar to how a statement starting with ` switch ` or ` { ` are
601+ parsed as a switch statement or a block, never as an expression statement.*
602+
593603* Another special exception is introduced with factory constructors in order
594604to avoid breaking existing code:*
595605
596- A factory constructor declaration of the form ` factory C(... ` where ` C `
606+ A factory constructor declaration of the form ` factory C(... ` including
607+ zero or more of the modifiers ` const ` , ` augment ` , or ` external ` where ` C `
597608is the name of the enclosing class, mixin class, enum, or extension type is
598609treated as if ` C ` had been omitted.
599610
@@ -856,7 +867,9 @@ Finally, _k2_ is added to _D2_, and _D_ is replaced by _D2_.
856867This feature is language versioned.
857868
858869* It introduces a breaking change in the grammar, which implies that
859- developers must explicitly enable it. In particular, ` factory() {} ` in a
870+ developers must explicitly enable it. In particular, the feature disallows
871+ ` var x ` , ` final x ` , and ` final T x ` as formal parameter declarations in all
872+ functions that are not primary constructors. Moreover, ` factory() {} ` in a
860873class body used to be a method declaration whose name is ` factory ` . With
861874this feature, it is a factory constructor declaration whose name is the
862875name of the enclosing class, enum, or extension type declaration.*
0 commit comments