[Issue 22135] New: Spurious "has scoped destruction, cannot build closure" on mixing closures, tuples and destructor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 22 09:20:59 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22135

          Issue ID: 22135
           Summary: Spurious "has scoped destruction, cannot build
                    closure" on mixing closures, tuples and destructor
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: industry
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: pro.mathias.lang at gmail.com

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.

--


More information about the Digitalmars-d-bugs mailing list