From 8038ad4e58a628a6ee6fde09f4ec8b565368428d Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 26 Feb 2025 03:20:24 +0800 Subject: [PATCH] fixes #12340; enable refc with move analyzer (#23782) fixes https://github.com/nim-lang/Nim/issues/12340 (cherry picked from commit a7a8e364ea466223cb212dcefd5ff401266f5250) --- compiler/sempass2.nim | 5 +++-- tests/collections/tseq.nim | 8 ++++++++ tests/stdlib/tmarshal.nim | 4 +++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index 4122ec2fd6..6730861d81 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -137,8 +137,9 @@ proc createTypeBoundOps(tracked: PEffects, typ: PType; info: TLineInfo; explicit createTypeBoundOps(tracked.graph, tracked.c, realType.lastSon, info) createTypeBoundOps(tracked.graph, tracked.c, typ, info, tracked.c.idgen) - if (tfHasAsgn in typ.flags) or - optSeqDestructors in tracked.config.globalOptions: + if tracked.config.selectedGC == gcRefc or + optSeqDestructors in tracked.config.globalOptions or + tfHasAsgn in typ.flags: tracked.owner.flags.incl sfInjectDestructors proc isLocalSym(a: PEffects, s: PSym): bool = diff --git a/tests/collections/tseq.nim b/tests/collections/tseq.nim index 0f8084c787..ee5f47a3b1 100644 --- a/tests/collections/tseq.nim +++ b/tests/collections/tseq.nim @@ -240,3 +240,11 @@ block: # bug #17197 result = true doAssert needlemanWunsch("ABC", "DEFG", 1, 2, 3) + +block: # bug #12340 + func consume(x: sink seq[int]) = + x[0] += 5 + + let x = @[1, 2, 3, 4] + consume x + doAssert x == @[1, 2, 3, 4] diff --git a/tests/stdlib/tmarshal.nim b/tests/stdlib/tmarshal.nim index 32991ccc91..5bdbc6bdec 100644 --- a/tests/stdlib/tmarshal.nim +++ b/tests/stdlib/tmarshal.nim @@ -1,7 +1,9 @@ discard """ - matrix: "--mm:orc; --mm:refc" + matrix: "--mm:orc" """ +# TODO: --mm:refc + import std/marshal import std/[assertions, objectdollar, streams]