fixes lifting subtype calling parent's hooks (#23612)

ref https://forum.nim-lang.org/t/11587

Tested with `gcc version 14.0.1 20240412` locally
This commit is contained in:
ringabout
2024-05-16 02:52:18 +08:00
committed by GitHub
parent c08356865d
commit 2c8551556e
2 changed files with 28 additions and 2 deletions

View File

@@ -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) =

View File

@@ -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()