-
Couldn't load subscription status.
- Fork 227
Update declaring constructors to allow the new constructor syntax #4543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Testing the libraries in A couple of errors arise because the test specifically tests the treatment of built-in identifiers and reserved words, so that's to be expected. The remaining errors are all concerned with the use of We could try out the radical approach (making |
c1abdba to
19471aa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
| <classDeclaration> ::= // First alternative modified. | ||
| (<classModifiers> | <mixinClassModifiers>) | ||
| 'class' <classNamePart> <superclass>? <interfaces>? <classBody> | ||
| 'class' <classNameMaybePrimary> <superclass>? <interfaces>? <classBody> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion/nit: "maybe" implies "optional" to me but not a choice from two alternatives. Perhaps a better name is "classNameOrPrimary"?
| <typeIdentifier> <typeParameters>? | ||
| ('.' <identifierOrNew>)? <declaringParameterList> | ||
| <primaryConstructor> ::= // New rule. | ||
| 'const'? <typeWithParameters> ('.' <identifierOrNew>)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, I never thought there was value in supporting Foo.new in constructor declarations, and we don't necessarily have to support it for primary constructors. We could just do ('.' <identifier>) here.
But if you think it's worth it for consistency, I could go either way. :)
| *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.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be explicit here that this is a language versioned change. We'd say that factory is a built-in identifier in pre-feature libraries and a reserved word in later versions.
| <constantConstructorSignature> ::= // Modified rule. | ||
| : 'const' <constructorName> <formalParameterList> // Old form. | ||
| | 'const' <constructorHead> <formalParameterList> // New form. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the "old form" / "new form" comments are very helpful here.
See #4485 for background information.
This PR changes the feature specification of declaring constructors such that its grammar rules support the new style of constructor declarations (like
new();andconst factory name() = D;).It handles the ambiguity among
factory();being a method or a factory constructor declaration whose name is the name of the enclosing class/mixin-class/enum/extension-type declaration by makingfactorya reserved word.