[Issue 8621] New: Iterattion variable in foreach not closed upon properly in delegate

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Sep 5 02:49:20 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8621

           Summary: Iterattion variable in foreach not closed upon
                    properly in delegate
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrei at metalanguage.com


--- Comment #0 from Andrei Alexandrescu <andrei at metalanguage.com> 2012-09-05 02:49:47 PDT ---
Consider:

import std.stdio;

void main() {
    void delegate()[] a;
    foreach (i; 1 .. 10) {
        a ~= { writeln(i); };
    }
    foreach (f; a) {
        f();
    }
}

This program prints an arbitrary value every run, which means i is not properly
closed upon.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list