Skip to content

Let c1[c2] be a compile time constant expression. #21625

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

Closed
lrhn opened this issue Nov 16, 2014 · 2 comments
Closed

Let c1[c2] be a compile time constant expression. #21625

lrhn opened this issue Nov 16, 2014 · 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 Nov 16, 2014

If c1 is a compile-time constant List, Map or String, and c2 is a compile-time constant too, we could allow c1[c2] as a compile-time constant expression.

It will throw if c1 is a List or String and c2 is not an integer or it is < 0 or >= c1.length. The result is either the element at index c2, if c1 is a List, or the substring of length 1 at index c2 when c1 is a String.

If c1 is a Map, any key is allowed, and c1[c2] evaluates to null if c2 isn't a key in the map - since the keys of a constant map must not override operator==, the lookup is a safe constant operation.

@DartBot
Copy link

DartBot commented Nov 17, 2014

This comment was originally written by trpasl...@gmail.com


possibe duplicate of https://code.google.com/p/dart/issues/detail?id=18389

@lrhn
Copy link
Member Author

lrhn commented Nov 18, 2014

It is a duplicate, only with only the addition of String indexing. Merging with older issue.


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

@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 Nov 18, 2014
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed priority-unassigned 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