Bug 22135 – Spurious "has scoped destruction, cannot build closure" on mixing closures, tuples and destructor

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-07-22T09:20:59Z
Last change time
2024-12-13T19:17:37Z
Keywords
industry
Assigned to
No Owner
Creator
Mathias LANG
Moved to GitHub: dmd#19961 →

Comments

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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19961 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB