make fillObjectFields recur over base type (#24854)

fixes #24847

Object constructors call `fillObjectFields` when a field inside the
constructor does not have a location, however when the field is from a
base type this does not process it. Now `fillObjectFields` also calls
itself for the base type to fix this but not sure if this is a good
solution as `fillObjectFields` is used in other places too.

(cherry picked from commit a625fab098)
This commit is contained in:
metagn
2025-04-08 17:00:58 +03:00
committed by narimiran
parent e2bf3a6f70
commit 574db65396
2 changed files with 32 additions and 0 deletions

View File

@@ -768,6 +768,8 @@ proc fillObjectFields*(m: BModule; typ: PType) =
# this fact here.
var check = initIntSet()
discard getRecordFields(m, typ, check)
if typ.baseClass != nil:
fillObjectFields(m, typ.baseClass.skipTypes(skipPtrs))
proc mangleDynLibProc(sym: PSym): Rope

30
tests/objects/t24847.nim Normal file
View File

@@ -0,0 +1,30 @@
# issue #24847
block: # original issue test
type
R[C] = ref object of RootObj
b: C
K[S] = ref object of R[S]
W[J] = object
case y: bool
of false, true: discard
proc e[T]() = discard K[T]()
iterator h(): int {.closure.} = e[W[int]]()
let _ = h
type U = distinct int
e[W[U]]()
block: # simplified
type
R[C] = ref object of RootObj
b: C
K[S] = ref object of R[S]
W[J] = object
case y: bool
of false, true: discard
type U = distinct int
discard K[W[int]]()
discard K[W[U]]()