Skip to content

Commit 240c838

Browse files
authored
Refresh the primary constructor proposal to use new syntax (#4428)
This PR adjusts the primary constructor proposal to use the approach where the in-header form is considered to be syntactic sugar for an in-body form ("just move the parameter list to the header"). In particular, this allows even the in-header constructor to have all features (initializer list, superinitializer, body), declared in the body. It does not introduce abbreviations of non-primary constructor declarations (like const(); as a short form for const MyClass();). That's a separate feature which can be handled elsewhere. The description of the parameter list as "being moved to the header" implies that the parameter list will have the same semantics when declared in-body and in-header. In particular, the in-header form does require an explicit token for a parameter to be declaring (`var` or `final`), and it does support non-declaring parameters even in the header. The `const` modifier can remain in the body, such that primary constructors are as similar to other constructors as they can be. It can also be specified in the header, such that tiny data classes can have a constant constructor without needing a body. This PR only updates the introduction and the grammar, the remaining parts will be updated in a separate PR.
1 parent 270288d commit 240c838

File tree

1 file changed

+186
-133
lines changed

1 file changed

+186
-133
lines changed

0 commit comments

Comments
 (0)