This is just a meta issue to track overall progress and bugs tied to pushing optional new and const in Dart & Flutter.
new and const.] (https://github.com/dart-lang/sdk/issues/30922)We should probably also track the long-term work regarding what people are calling "magic const", which is to say, automatically implying "const" instead of "new" where possible.
Also, will the analyzer have a lint that recommends removing new and const where they would be implied?
Drive-by comment: A lint that recommends omitting a const which occurs in a constant context is completely safe (presumably, nobody would have a good reason to have it there), but insisting that you omit all new keywords just because you can may be overly strict: During discussions in the language team about this feature it was noted several times, by several parties, that a well-placed new may serve to document that a particular object is fresh, and that this could improve the readability of the code.
With a possibly upcoming generalization that reintroduces "magic" const, it would again serve to insist that a given object is created at run time, which might otherwise not be expressible. E.g., when new Object() is used to obtain an object reference which is different from all other object references (e.g., to be used as a key in a map), it cannot be left as a plain Object() because that would mean const Object() (at least at some point in the future).
@Hixie do you mean something like https://github.com/dart-lang/linter/pull/936 ?
@eernstg In all likelihood for Flutter at least we'd probably just create special non-const constructors for those rare cases where calling "new" instead of "const" makes sense.
@a14n Yeah that seems good.
@Hixie will create a separate issue for the long term "magic const"
For now, I'll close this as this was a meta issue to track to work that we need to get all the issues for our next flutter roll.
Most helpful comment
@eernstg In all likelihood for Flutter at least we'd probably just create special non-const constructors for those rare cases where calling "new" instead of "const" makes sense.
@a14n Yeah that seems good.