fixes #26024; sink + no-copy type copies type in refc

This commit is contained in:
ringabout
2026-07-28 21:00:24 +08:00
parent 2d81149294
commit 4734c2f5d7
2 changed files with 24 additions and 1 deletions

View File

@@ -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)

16
tests/arc/torc_refc.nim Normal file
View File

@@ -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()