You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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..
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.
The text was updated successfully, but these errors were encountered: