Skip to content

Commit

Permalink
fixes #23505; fixes injectdestructors errors on transformed addr (der…
Browse files Browse the repository at this point in the history
…ef) refs (#23507)

fixes #23505
  • Loading branch information
ringabout committed Apr 18, 2024
1 parent 49e1ca0 commit acd4c8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/injectdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions tests/arc/tarcmisc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit acd4c8a

Please sign in to comment.