[Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Aug 14 20:05:25 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2043
------- Comment #2 from bugzilla at digitalmars.com 2008-08-14 22:05 -------
Here's a better illustration of the problem:
void delegate() dg;
void main()
{
foreach(int i; 0 .. 2)
{
invariant int b = i;
if (i == 0)
dg = { printf("b = %d\n", b); };
dg();
}
dg();
}
'b' is supposed to be invariant, yet its value (as seen by dg()) changes. One
possible fix for this is to make invariants that are initialized with varying
values be illegal to reference from a delegate.
--
More information about the Digitalmars-d-bugs
mailing list