Testcase: ``` alias AliasSeq(TList...) = TList; import core.stdc.stdio; int i = 0; struct A { ~this() { printf("~this\n"); i *= 2; } } void main() { { AliasSeq!(A, A) params; printf("statement\n"); i = 1; } printf("%d\n", i); assert(i == 4); } ``` The assertion fails. Looking at the printout: ``` ~this ~this statement 1 ``` you can see that the dtors are called before the statement `i = 1;`, instead of at the end of the scope.
The problem seems to be that the frontend treats/sets up the tuple as a temporary variable (valid for the duration of that expression only), instead of generating the ~this() calls at end of scope like it does for normal variables.
You're right. I'll look into why this is happening.
*** Issue 17128 has been marked as a duplicate of this issue. ***
*** Issue 20135 has been marked as a duplicate of this issue. ***
@BorisCarvajal created dlang/dmd pull request #15351 "Fix Issue 24010 - Destructor called before end of scope for tuples" fixing this issue: - Fix Issue 24010 - Destructor called before end of scope for tuples https://github.com/dlang/dmd/pull/15351
@WalterBright created dlang/dmd pull request #15366 "fix Issue 24010 - Destructor called before end of scope for tuples" fixing this issue: - fix Issue 24010 - Destructor called before end of scope for tuples https://github.com/dlang/dmd/pull/15366
dlang/dmd pull request #15351 "Fix Issue 24010 - Destructor called before end of scope for tuples" was merged into master: - 597e133324fac8c1ded4d93186969727fd095fa7 by Boris Carvajal: Fix Issue 24010 - Destructor called before end of scope for tuples Co-authored-by: Walter Bright <walter@walterbright.com> https://github.com/dlang/dmd/pull/15351