Comment #0 by pro.mathias.lang — 2021-07-22T09:20:59Z
See the following code example:
```D
// Need something with a destructor
struct S { ~this () {} }
// Need a tuple (??)
alias AliasSeq(T...) = T;
// Need to return a nested function
alias DG = void delegate ();
DG func()
{
Server inst;
// Providing `-version=NoTuple` makes the error go away
// So does providing `-version=NoDirectCall`.
version (NoTuple)
alias PTypes = S;
else
alias PTypes = AliasSeq!(S);
void handler() {
// Error: variable `func.handler.__params_field_0` has scoped destruction, cannot build closure
PTypes params;
version (NoDirectCall)
inst.foo(params);
else
() @trusted { inst.foo(params); } ();
}
return &handler;
}
struct Server {
void foo (S param) {} // Can be `ref` too, no difference
}
void main ()
{
auto dg = func();
}
```
As mentioned, compiling with either `-version` makes the error go away.
Comment #1 by robert.schadek — 2024-12-13T19:17:37Z