Bug 21067 – Tupleof of struct returned by function with string field lazily passed to function, itself lazily passed to another function, causes runtime OOM.
Comment #0 by default_357-line — 2020-07-23T15:35:20Z
Consider the following, remarkable code:
struct S { int b; string s; }
S test() { return S(); }
void main()
{
evalArg(dupArg2(test.tupleof));
}
void dupArg2(int, lazy string msg)
{
msg().dup;
}
void evalArg(lazy void expression)
{
try expression();
finally { }
}
When built and run with DMD, I get an OOM error.
LDC gives the somewhat more helpful error:
test.d(7): Error: function test.main.__dgliteral1 cannot access frame of function test.main.__dgliteral2
For the evalArg call. Indicating the issue is related to the double-nesting of lazy.
Comment #1 by default_357-line — 2020-07-23T15:41:07Z
A shorter version that "runs" with dmd, but preserves the ldc error:
struct S { int a; int b; }
S test() { return S(); }
void main() { evalArg(dupArg2(test.tupleof)); }
void dupArg2(int, lazy int) {}
void evalArg(lazy void) {}
Comment #2 by robert.schadek — 2024-12-13T19:10:18Z