Handle another corner case in recordFields

This commit is contained in:
Zahary Karadjov 2020-05-27 11:30:56 +03:00
parent 4ffd3e1f59
commit a99dafab42
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
2 changed files with 9 additions and 3 deletions

View File

@ -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]

View File

@ -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"
]