-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[proposal] add const
at compile time (where possible)
#56669
Comments
Summary: The issue proposes automatically making variables, constructors, and Flutter children |
This is not possible, it would at most be able to say that it could be constant, based on a local analysis. The reason for this is that it can make a difference semantically whether any given expression is marked with void main() {
var xs = <int>[]; // means `const <int>[]`?
xs.add(1); // Succeeds if `<int>[]`, throws if `const <int>[]`.
} This is exactly the reason why I'm proposing that a developer must use their knowledge about the design of the enclosing software and make the choice to put a |
The issue dart-lang/language#1410 has more discussion about the implications of this request. |
Another approach is to change the language to have more contexts that are TL;DR:
|
related issues
const
ness flutter/flutter#149932note quote from the former
proposal
if a linter is able to tell if a variable, a constructor or (in flutter) a child should be a constant,
wouldn't be more developer friendly to automatically make it a constant at compile time
without (quote) "nagging developers"
The text was updated successfully, but these errors were encountered: