The following test case, an adapted version of runnable/test10981.d, fails using DMD 2.070 (OS X, but that's irrelevant):
---
auto foo(int i)
{
class X1
{
void in_nested() in {
import core.stdc.stdio;
printf("%d\n", i);
assert(i);
} body {}
}
return new X1;
}
void main() {
auto a = foo(1234);
a.in_nested();
}
---
The problem seems to be that the frontend assumes that variable references from contracts *never* make the variable in question a closureVar, irrespective of whether the variable accessed is in the direct parent function or further up the chain.
[1] https://github.com/D-Programming-Language/dmd/blob/9d1edd1e78031e5760cc7cf923dd0bf9b1f8e7e6/src/declaration.d#L2232
Comment #1 by robert.schadek — 2024-12-13T18:46:46Z