language icon indicating copy to clipboard operation
language copied to clipboard

Bugs in the spec for for loops

Open kmillikin opened this issue 8 years ago • 2 comments

The spec for for loops describes a statement of the form for (var v = e0; c; e) s. There are some missing cases:

  1. Multiple variables can be declared, but the spec only mentions one. The reader might infer either that multiple variables are treated uniformly, or else that the first one is special.
  2. There can be an expression instead of a variable declaration for the initializer. Presumably this is just evaluated and all the fresh variable/substitution stuff can be ignored.
  3. The initializer can be empty. There is otherwise no "empty expression" in Dart so the reader might wonder what happens in that case.
  4. The update is a possibly-empty sequence of expressions, and the spec does not otherwise define evaluation of a sequence of expressions. The definition of for loops just says 'the expression [v''/v]e is evaluated'. We need to say at least that this is left to right.

Also problematic is: "First the variable declaration statement var v = e0 is executed." There is no mention that this is in its own scope, and so by the normal scoping rules it would introduce a variable v to the block containing the for loop, initialized at the for loop, and thus accessible after the loop. This does not seem to be the intent.

kmillikin avatar Mar 08 '16 14:03 kmillikin

Declarations could also be final or const. I can't immediately think of a way that it could be observed, but we should say whether they are fresh variables per iteration or not or else explicitly say that it should not matter. Such code might not be useful for a programmer but I could imagine a code generator that might produce it.

Declarations can be typed. We should say that the static type of all the fresh variables is the same as the declared type (which I think is the intent) or what the static type is.

kmillikin avatar Mar 09 '16 12:03 kmillikin

No milestone now: The corrections and clarifications should be carried out, but it does not block Dart 2.

eernstg avatar Feb 06 '18 16:02 eernstg