www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22135] New: Spurious "has scoped destruction, cannot build


          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 puremagic.com
          Reporter: pro.mathias.lang gmail.com

See the following code example:

// 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;
            alias PTypes = AliasSeq!(S);

    void handler() {
        //  Error: variable `func.handler.__params_field_0` has scoped
destruction, cannot build closure
        PTypes params;
        version (NoDirectCall)
                ()  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.

Jul 22