Bug 2228 – Full closure does not honor loop context
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2008-07-15T13:17:00Z
Last change time
2015-06-09T01:19:35Z
Assigned to
bugzilla
Creator
benoit
Comments
Comment #0 by benoit — 2008-07-15T13:17:05Z
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.
Comment #1 by bruno.do.medeiros+deebugz — 2008-07-27T12:23:50Z
My example is a bit less clear, but it's the same bug.
*** This bug has been marked as a duplicate of 2043 ***