-
Notifications
You must be signed in to change notification settings - Fork 209
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
Enhanced Constructors #4246
Comments
Also a sketch of a similar feature here: #3002 I like the proposal. It handles all the tricky parts (I think). I would suggest allowing const constructor bodies to also declare local final or const variables. That would finally avoid needing a redirect to introduce a named value that needs to be accessed from two initializer list entries. I worry about closures created before the super constructor invocation. Or in short: If you can close over (The things I really want closures for are not things that can be allowed before being fully initialized.) Hmm. Could you close over reading a late variable with an initializer expression? (Because those can refer to |
I love it. Ship it!
I think this restriction would be annoying. It's a feature of this proposal that it enables users to do control flow in order to initialize fields. That's one of the main reasons I end up writing a factory constructor that forwards to a generative constructor. |
This feature proposal extends the set of actions that can be performed in the body of a non-redirecting generative constructor to include writing to non-late final fields and explicitly invoking super constructors.
This makes constructors more flexible, avoids the need for constructor initializer lists, and allows constructor augmentations to behave more consistently with function augmentations.
To preserve soundness, flow analysis is enhanced to ensure that a reference to
this
cannot escape from a constructor body before the object has been completely constructed.For details please see https://github.com/dart-lang/language/blob/main/working/enhanced-constructors/feature-specification.md
The text was updated successfully, but these errors were encountered: