[Issue 2228] New: Full closure does not honor loop context

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jul 15 11:17:07 PDT 2008


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

           Summary: Full closure does not honor loop context
           Product: D
           Version: 2.015
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: benoit at tionex.de


With DMD 2.015:

alias void delegate() Runner;
void main(){
  Runner[] runners;
  for( int i = 0; i < 3; i++ ){
    const int ci = i;
    runners ~= delegate(){
      writefln( "run with ci=%d", ci );
    };
  }
  foreach( runner; runners ){
    runner();
  }
}


Output:
run with ci=2
run with ci=2
run with ci=2

It should be 0,1,2.


-- 



More information about the Digitalmars-d-bugs mailing list