Skip to content
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

Allow omitting 'const' from List/Map(/Constructor?) literals inside a known const context. #4803

Closed
lrhn opened this issue Aug 29, 2012 · 2 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug

Comments

@lrhn
Copy link
Member

lrhn commented Aug 29, 2012

To write a const list of lists, you need to prefix every constant list with 'const', e.g.:
  const [const [1,2], const [3,4], const [5,6]]
The inner 'const' are really superfluous, since it would currently be an error to omit them.
We could allow omitting these extra 'const' markers and automatically assume that any List or Map literal inside a const literal is itself const. That is, allow:
  const [[1,2], [3,4], [5,6]]
to mean the same thing as the above.
This would:
a) make it much easier to write larger const structures by hand, and
b) make it easier to transform a JSON value to a const (just add 'const' in front, and escape '$' in strings)

Optionally, we can also allow removing 'const' in front of 'const Foo(a,b)' inside a const literal. This would match the missing 'const' in front of meta-data annotation, where we allow it to be omitted because we know it's a const-context.

We could even make the initial const optional in a known const context, so it's just "static const List foo = [1,2,3]" ... but that's probably a more serious change, since it can more easily hide bugs.

@DartBot
Copy link

DartBot commented Aug 31, 2012

This comment was originally written by @seaneagan


dupe of issue #4046 ?

@lrhn
Copy link
Member Author

lrhn commented Sep 3, 2012

Absolutely a dupe. I failed to find the original with a search, and convinced myself it had probably been a mailing list discussion.


Added Duplicate label.
Marked as being merged into #4046.

@lrhn lrhn added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report labels Sep 3, 2012
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants