-
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
const at the top level of a structure should propagate down #4046
Comments
Added Area-Language, Triaged labels. |
This comment was originally written by @seaneagan I really like this. The main problem is what do you use instead of "const" for the nested constructor calls? Using "new" wouldn't look right. Using nothing is better, but then it isn't consistent with constructor calls elsewhere. I think this is yet another reason to remove the "new" keyword (and factory constructors as they would no longer be needed). This would really help out with making annotations more terse and readable: @SomeAnnotation(const Foo(const Bar(), const Baz()) @SomeAnnotation(Foo(Bar(), Baz()) |
You can change const expressions without changing non-const constructor calls. |
This comment was originally written by @seaneagan What I meant to say is that bare (without "new" or "const") constructor calls would look weird inside these proposed "const" expressions... unless they were the norm in the language, as would be the case if "new" were removed. |
This comment was originally written by @seaneagan Then there would be no special syntax needed inside of "const" expressions, it would just implicitly apply "const" modifiers to everything. |
Set owner to @gbracha. |
Issue #3974 has been merged into this issue. cc @sigmundch. |
Issue #4803 has been merged into this issue. |
This would be great in metadata annotations where we don't require const for the constructor, but then require it for arguments. |
This comment was originally written by @seaneagan Example user confusion here: http://stackoverflow.com/questions/20223354/custom-metadata-with-unknown-parameter-length |
Removed this from the Later milestone. |
Issue #20021 has been merged into this issue. |
Removed Oldschool-Milestone-Later label. |
I guess the link provides more value here than in #24620. I was sure I have seen the proposal but wasn't able to find it. |
This feature is now an accepted part of Dart 2. The feature specification implicit-creation.md gives the details, but the following is a good starting point:
So |
I have some large objects which are constant. As it stands, writing one of these out requires 22 occurrences of the word "const", one for every field (which isn't a string literal or number, because those are implicitly const and it's an error to write it explicitly).
It is not legal to write a const constructor call, literal Map or literal List containing non-const expressions. So it seems unnecessary to require a const annotation on the individual pieces. They are required to be const, so we should just enforce that they are without requiring the developer to also spell it out. That is to say, instead of having to write
var list = const [ const ['a'], const ['b'], const ['c']];
I should be able to write
var list = const [ ['a'], ['b'], ['c']];
there the outer const also applies to the inner lists. And the same for maps and const constructor invocations.
The text was updated successfully, but these errors were encountered: