fixes #26133; Side effects not checked in =destroy

This commit is contained in:
ringabout
2026-08-25 22:03:36 +08:00
parent 31215b3856
commit 5151e686a7
2 changed files with 19 additions and 0 deletions

View File

@@ -129,6 +129,8 @@ proc collectObjectTree(graph: ModuleGraph, n: PNode) =
else:
graph.objectTree[root].add (depthLevel, typ)
proc markSideEffect(a: PEffects; reason: PNode | PSym; useLoc: TLineInfo)
proc createTypeBoundOps(tracked: PEffects, typ: PType; info: TLineInfo; explicit = false) =
if typ == nil or (sfGeneratedOp in tracked.owner.flags and not explicit):
# don't create type bound ops for anything in a function with a `nodestroy` pragma
@@ -147,6 +149,10 @@ proc createTypeBoundOps(tracked: PEffects, typ: PType; info: TLineInfo; explicit
if op != nil and sfNeverRaises notin op.flags:
tracked.canRaiseDefect = true
break
let destructor = getAttachedOp(tracked.graph, typ, attachedDestructor)
if destructor != nil and sfOverridden in destructor.flags and
tfNoSideEffect notin destructor.typ.flags:
markSideEffect(tracked, destructor, info)
if tracked.config.selectedGC == gcRefc or
optSeqDestructors in tracked.config.globalOptions or
tfHasAsgn in typ.flags:

13
tests/effects/t26133.nim Normal file
View File

@@ -0,0 +1,13 @@
discard """
cmd: "nim check --hints:off $file"
errormsg: "'del' can have side effects"
file: "system.nim"
"""
type MyObject = object
proc `=destroy`(v: var MyObject) =
echo "hello"
func remove(v: var seq[MyObject]) =
v.del(0)