fixes #26023; incorrect sink requires a copy

This commit is contained in:
ringabout
2026-07-20 20:58:43 +08:00
parent 2463ef970d
commit 7349b1e4db
3 changed files with 24 additions and 4 deletions

View File

@@ -606,10 +606,16 @@ proc setHookDisamb*(g: ModuleGraph; hook: PSym; opName: string; typ: PType) =
break
hook.disamb = h
proc hasDisabledAsgn*(g: ModuleGraph; t: PType): bool =
let op = getAttachedOp(g, t, attachedAsgn)
proc hasDisabledOp(g: ModuleGraph; t: PType; kind: TTypeAttachedOp): bool =
let op = getAttachedOp(g, t, kind)
result = op != nil and sfError in op.flags
proc hasDisabledAsgn*(g: ModuleGraph; t: PType): bool =
result = hasDisabledOp(g, t, attachedAsgn)
proc hasDisabledDup*(g: ModuleGraph; t: PType): bool =
result = hasDisabledOp(g, t, attachedDup)
proc copyTypeProps*(g: ModuleGraph; module: int; dest, src: PType) =
for k in low(TTypeAttachedOp)..high(TTypeAttachedOp):
let op = getAttachedOp(g, src, k)

View File

@@ -1024,8 +1024,8 @@ proc computeCursors*(s: PSym; n: PNode; g: ModuleGraph) =
v.sym.flags * {sfThread, sfGlobal} == {} and
(hasDestructor(v.sym.typ) or (jsCursors and jsDeepCopied(v.sym.typ))) and
v.sym.typ.skipTypes({tyGenericInst, tyAlias}).kind != tyOwned and
(getAttachedOp(g, v.sym.typ, attachedAsgn) == nil or
sfError notin getAttachedOp(g, v.sym.typ, attachedAsgn).flags):
not hasDisabledAsgn(g, v.sym.typ) and
not hasDisabledDup(g, v.sym.typ):
let rid = root(par, i)
if par.s[rid].con.kind == isRootOf and dangerousMutation(par.graphs[par.s[rid].con.graphIndex], par.s[i]):
discard "cannot cursor into a graph that is mutated"

View File

@@ -65,3 +65,17 @@ method handleConn*(myParam: PubSub,
proto: string) {.base, async.} =
myParam.peers.withValue(conn.peerInfo.peerId, peer):
let peerB = peer[]
block:
type M = object
proc `=dup`(_: M): M {.error.}
proc take(_: sink M) = discard
proc test() =
var value: M
take(value)
test()