From 4734c2f5d7af5a3213b84df12da6b0af589519cb Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 28 Jul 2026 21:00:24 +0800 Subject: [PATCH] fixes #26024; sink + no-copy type copies type in refc --- compiler/liftdestructors.nim | 9 ++++++++- tests/arc/torc_refc.nim | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/arc/torc_refc.nim diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index aa8a20bc2a..e0588ecb88 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -75,6 +75,11 @@ proc newAsgnStmt(le, ri: PNode): PNode = result[0] = le result[1] = ri +proc newSinkAsgnStmt(le, ri: PNode): PNode = + result = newNodeI(nkSinkAsgn, le.info, 2) + result[0] = le + result[1] = ri + proc genBuiltin*(g: ModuleGraph; idgen: IdGenerator; magic: TMagic; name: string; i: PNode): PNode = result = newNodeI(nkCall, i.info) result.add createMagic(g, idgen, name, magic).newSymNode @@ -84,7 +89,9 @@ proc genBuiltin(c: var TLiftCtx; magic: TMagic; name: string; i: PNode): PNode = result = genBuiltin(c.g, c.idgen, magic, name, i) proc defaultOp(c: var TLiftCtx; t: PType; body, x, y: PNode) = - if c.kind in {attachedAsgn, attachedDeepCopy, attachedSink, attachedDup}: + if c.kind == attachedSink: + body.add newSinkAsgnStmt(x, y) + elif c.kind in {attachedAsgn, attachedDeepCopy, attachedDup}: body.add newAsgnStmt(x, y) elif c.kind == attachedDestructor and c.addMemReset: let call = genBuiltin(c, mDefault, "default", x) diff --git a/tests/arc/torc_refc.nim b/tests/arc/torc_refc.nim new file mode 100644 index 0000000000..02ae6ec943 --- /dev/null +++ b/tests/arc/torc_refc.nim @@ -0,0 +1,16 @@ +discard """ + matrix: "--mm:orc; --mm:refc" +""" + +type M = object + y: seq[int] +proc `=copy`(_: var M, _: M) {.error.} +proc `=dup`(_: M): M {.error.} +proc k(v: sink M): M = v +proc w() = + var t = M(y: @[0]) + let s = addr t.y[0] + t = k(t) + s[] = 1 + doAssert t.y[0] != 0 +w() \ No newline at end of file