Handle another corner case in recordFields
This commit is contained in:
parent
4ffd3e1f59
commit
a99dafab42
|
@ -160,6 +160,8 @@ proc collectFieldsInHierarchy(result: var seq[FieldDescription],
|
|||
objectType: NimNode) =
|
||||
var objectType = objectType
|
||||
|
||||
objectType.expectKind {nnkObjectTy, nnkRefTy}
|
||||
|
||||
if objectType.kind == nnkRefTy:
|
||||
objectType = objectType[0]
|
||||
|
||||
|
@ -173,7 +175,7 @@ proc collectFieldsInHierarchy(result: var seq[FieldDescription],
|
|||
baseType = getImpl(baseType)
|
||||
baseType.expectKind nnkTypeDef
|
||||
baseType = baseType[2]
|
||||
baseType.expectKind nnkObjectTy
|
||||
baseType.expectKind {nnkObjectTy, nnkRefTy}
|
||||
collectFieldsInHierarchy result, baseType
|
||||
|
||||
let recList = objectType[2]
|
||||
|
|
|
@ -17,6 +17,9 @@ type
|
|||
DerivedType = ref object of BaseType
|
||||
derivedField: int
|
||||
|
||||
DerivedFromRefType = ref object of DerivedType
|
||||
anotherDerivedField: string
|
||||
|
||||
macro getFieldsLists(T: type): untyped =
|
||||
result = newTree(nnkBracket)
|
||||
|
||||
|
@ -29,10 +32,11 @@ macro getFieldsLists(T: type): untyped =
|
|||
result.add newLit($f.name)
|
||||
|
||||
static:
|
||||
doAssert getFieldsLists(DerivedType) == [
|
||||
doAssert getFieldsLists(DerivedFromRefType) == [
|
||||
"baseField",
|
||||
"baseCaseField",
|
||||
"baseA",
|
||||
"derivedField"
|
||||
"derivedField",
|
||||
"anotherDerivedField"
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in New Issue