[Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly: should have multiple instances but only have one.

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Oct 2 10:16:17 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=2043

--- Comment #16 from entheh at cantab.net ---
Unfortunately I have a feeling there will be people relying on being able to do
this kind of thing (though I'm not 100% sure if it currently works):

foreach (i; 0..10) {
  ...
  if (somethingStrangeHappens) {
    //Try again with the same 'i'
    i--;
    continue;
  }
}

If 'i' became a new variable for each iteration, then the modify-assign would
not have the effect intended. Do we need to make 'i' implicitly final to
protect against this?

--


More information about the Digitalmars-d-bugs mailing list