fixes #23505; fixes injectdestructors errors on transformed addr (deref) refs (#23507)

fixes #23505
This commit is contained in:
ringabout
2024-04-18 17:57:44 +08:00
committed by GitHub
parent 49e1ca0b3e
commit acd4c8a353
2 changed files with 17 additions and 1 deletions

View File

@@ -412,7 +412,10 @@ proc genDefaultCall(t: PType; c: Con; info: TLineInfo): PNode =
proc destructiveMoveVar(n: PNode; c: var Con; s: var Scope): PNode =
# generate: (let tmp = v; reset(v); tmp)
if (not hasDestructor(c, n.typ)) and c.inEnsureMove == 0:
assert n.kind != nkSym or not hasDestructor(c, n.sym.typ)
assert n.kind != nkSym or not hasDestructor(c, n.sym.typ) or
(n.typ.kind == tyPtr and n.sym.typ.kind == tyRef)
# bug #23505; transformed by `transf`: addr (deref ref) -> ptr
# we know it's really a pointer; so here we assign it directly
result = copyTree(n)
else:
result = newNodeIT(nkStmtListExpr, n.info, n.typ)

View File

@@ -714,3 +714,16 @@ block:
let c: uint = 300'u
doAssert $arrayWith(c, 3) == "[300, 300, 300]"
block: # bug #23505
type
K = object
C = object
value: ptr K
proc init(T: type C): C =
let tmp = new K
C(value: addr tmp[])
discard init(C)