https://issues.dlang.org/show_bug.cgi?id=2043
[email protected] changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #13 from [email protected] --- Note that this bug breaks immutability: --------- import std.stdio; void main() { void delegate()[] a; foreach (i; 1 .. 10) { immutable j = i; writeln(j); a ~= { writeln(j); }; } writeln("---"); foreach (f; a) { f(); } } --------- Output: --------- 1 2 3 4 5 6 7 8 9 --- 9 9 9 9 9 9 9 9 9 --------- Notice that in each iteration of the loop, we are closing on the immutable value j, which is set to the loop counter. However, the output shows that the value of j has changed since the delegates were initialized. In fact, it changes at every iteration. This violates the guarantee of immutable. --
