Skip to content

Commit

Permalink
fixes lifting subtype calling parent's hooks (#23612)
Browse files Browse the repository at this point in the history
ref https://forum.nim-lang.org/t/11587

Tested with `gcc version 14.0.1 20240412` locally
  • Loading branch information
ringabout committed May 15, 2024
1 parent c083568 commit 2c85515
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 4 additions & 1 deletion compiler/liftdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ proc fillBodyObj(c: var TLiftCtx; n, body, x, y: PNode; enforceDefaultOp: bool)

proc fillBodyObjTImpl(c: var TLiftCtx; t: PType, body, x, y: PNode) =
if t.baseClass != nil:
fillBody(c, skipTypes(t.baseClass, abstractPtrs), body, x, y)
let obj = newNodeIT(nkHiddenSubConv, c.info, t.baseClass)
obj.add newNodeI(nkEmpty, c.info)
obj.add x
fillBody(c, skipTypes(t.baseClass, abstractPtrs), body, obj, y)
fillBodyObj(c, t.n, body, x, y, enforceDefaultOp = false)

proc fillBodyObjT(c: var TLiftCtx; t: PType, body, x, y: PNode) =
Expand Down
25 changes: 24 additions & 1 deletion tests/arc/tarc_orc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,27 @@ proc main2 =
doAssert a.len == 2
doAssert b.len == 0

main2()
main2()

block:
type
TestObj = object of RootObj
name: string

TestSubObj = object of TestObj
objname: string

proc `=destroy`(x: TestObj) =
`=destroy`(x.name)

proc `=destroy`(x: TestSubObj) =
`=destroy`(x.objname)
`=destroy`(TestObj(x))

proc testCase() =
let t1 {.used.} = TestSubObj(objname: "tso1", name: "to1")

proc main() =
testCase()

main()

0 comments on commit 2c85515

Please sign in to comment.