From 7bc6e416af6cfd7721e5504d1045f0bcbdd0916f Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 12 Aug 2026 22:20:26 +0800 Subject: [PATCH] progress --- compiler/injectdestructors.nim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index e490fd5ef2..d7bf5d02d3 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -529,14 +529,16 @@ proc containsConstSeq(n: PNode): bool = proc ensureDestruction(arg, orig: PNode; c: var Con; s: var Scope; consume = false): PNode = - # Give destructible expressions a scoped owner. If the expression is - # consumed, move it out and clear the temporary before its finalizer runs. + # it can happen that we need to destroy expression contructors + # like [], (), closures explicitly in order to not leak them. if arg.typ != nil and hasDestructor(c, arg.typ): # produce temp creation for (fn, env). But we need to move 'env'? # This was already done in the sink parameter handling logic. result = newNodeIT(nkStmtListExpr, arg.info, arg.typ) let tmp = c.getTemp(s, arg.typ, arg.info, true) result.add c.genSink(s, tmp, arg, {IsDecl}) + # In consumed mode, the destination takes ownership of the data. + # Clear the temporary after moving from it to prevent double destruction. result.add if consume: destructiveMoveVar(tmp, c, s) else: tmp s.final.add c.genDestroy(tmp) else: