From 0ccee3b4c23d1fa60f63510c75aafb96ab3a3e63 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sat, 7 Mar 2026 15:10:01 +0100 Subject: [PATCH] fixes #24746 (#25587) (cherry picked from commit 0395af2b3459837fcdf6bf8c38d470ee682dd9cd) --- compiler/injectdestructors.nim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index 5f863f323e..eb450e009f 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -1004,6 +1004,13 @@ proc p(n: PNode; c: var Con; s: var Scope; mode: ProcessMode; tmpFlags = {sfSing result = moveOrCopy(p(n[0], c, s, mode), n[1], c, s, flags) elif isDiscriminantField(n[0]): result = c.genDiscriminantAsgn(s, n) + elif n[1].kind in {nkStmtListExpr, nkBlockExpr, nkIfExpr, nkCaseStmt, nkTryStmt, nkPragmaBlock}: + # Distribute the assignment into each branch to avoid + # creating pointless temporaries for expression-based control flow. + let dest = p(n[0], c, s, mode) + template process(child, s): untyped = + newTree(n.kind, dest, p(child, c, s, consumed)) + handleNestedTempl(n[1], process, willProduceStmt = true) else: result = copyNode(n) result.add p(n[0], c, s, mode)