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

Loop variables cannot be const #5675

Closed
DartBot opened this issue Oct 5, 2012 · 3 comments
Closed

Loop variables cannot be const #5675

DartBot opened this issue Oct 5, 2012 · 3 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).

Comments

@DartBot
Copy link

DartBot commented Oct 5, 2012

This issue was originally filed by @mhausner


The grammar allows loop variables to be const, which does not make much sense. Unipro has tests that expect this code to work, since it's not expressly forbidden:

for (const e in const [1, 2, 3]) ...

Even with the list being const, the initializer value for e is never a const expression.

I'm filing this so Gilad can decide whether the spec should expressly forbid const in loop variables, either in the grammar or in the text.

See also co19 issue #240.

@gbracha
Copy link
Contributor

gbracha commented Jan 16, 2014

The spec should be clarified. It does say that initializing a const variable with a non-constant is a compile time error, so the code above should be rejected at compile time in any case. However, we should either change the grammar or make the spec clearer; the spec for for does not explicitly deal with these situations,a nd it probably should.


Added Accepted label.

@gbracha
Copy link
Contributor

gbracha commented Jan 17, 2014

Added Done label.

@eernstg
Copy link
Member

eernstg commented Sep 30, 2014

The following co19 test fails with dart2js, because it uses 'const' with the loop variable:

Language/13_Statements/06_For_A01_t11.

We could ask for an adjustment of the co19 test (removing the two statements with a const loop variable), and the compilers could be tested for actually raising this compile-time error, but the situation would be more well-defined if the spec were adjusted to mandate this compile-time error.

Alternatively, Peter Ahe mentioned that a const loop variable could be given a meaningful semantics, roughly, by considering a for statement iterating over a constant collection as equivalent to its full unfolding. This might be useful in some cases, but probably not very often..

@DartBot DartBot added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Sep 30, 2014
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).
Projects
None yet
Development

No branches or pull requests

4 participants