From 6828effd1358bab75e17f23ef91de44f4f433a53 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sat, 27 Jun 2026 01:57:03 +0800 Subject: [PATCH] Improve effect propagation by skipping hooks in trackCall (#25940) ref https://github.com/nim-lang/Nim/pull/25731 don't propagate effects for assignment hooks without effect lists --- compiler/sempass2.nim | 4 +++- tests/effects/thooks.nim | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index 8c740f54bf..008f2317ba 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -1197,7 +1197,9 @@ proc trackCall(tracked: PEffects; n: PNode) = else: if laxEffects notin tracked.c.config.legacyFeatures and a.kind == nkSym and a.sym.kind in routineKinds: - propagateEffects(tracked, n, a.sym) + let (isHook, opKind) = findHookKind(a.sym.name.s) + if (not isHook) or opKind notin {attachedAsgn, attachedSink, attachedDup}: + propagateEffects(tracked, n, a.sym) else: mergeRaises(tracked, effectList[exceptionEffects], n) mergeTags(tracked, effectList[tagEffects], n) diff --git a/tests/effects/thooks.nim b/tests/effects/thooks.nim index 23cc005cd1..393f8eff74 100644 --- a/tests/effects/thooks.nim +++ b/tests/effects/thooks.nim @@ -13,4 +13,12 @@ proc send(x: string) = let wrapper = Thing(x: x) discard isolate(wrapper) -send("la") \ No newline at end of file +send("la") + +block: + func enqueue[T](buf: var array[10, T], elem: sink T) = + `=sink`(buf[0], elem) + + var buf: array[10, int] + enqueue(buf, 42) + assert buf[0] == 42 \ No newline at end of file