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) =
|
objectType: NimNode) =
|
||||||
var objectType = objectType
|
var objectType = objectType
|
||||||
|
|
||||||
|
objectType.expectKind {nnkObjectTy, nnkRefTy}
|
||||||
|
|
||||||
if objectType.kind == nnkRefTy:
|
if objectType.kind == nnkRefTy:
|
||||||
objectType = objectType[0]
|
objectType = objectType[0]
|
||||||
|
|
||||||
|
@ -173,7 +175,7 @@ proc collectFieldsInHierarchy(result: var seq[FieldDescription],
|
||||||
baseType = getImpl(baseType)
|
baseType = getImpl(baseType)
|
||||||
baseType.expectKind nnkTypeDef
|
baseType.expectKind nnkTypeDef
|
||||||
baseType = baseType[2]
|
baseType = baseType[2]
|
||||||
baseType.expectKind nnkObjectTy
|
baseType.expectKind {nnkObjectTy, nnkRefTy}
|
||||||
collectFieldsInHierarchy result, baseType
|
collectFieldsInHierarchy result, baseType
|
||||||
|
|
||||||
let recList = objectType[2]
|
let recList = objectType[2]
|
||||||
|
|
|
@ -17,6 +17,9 @@ type
|
||||||
DerivedType = ref object of BaseType
|
DerivedType = ref object of BaseType
|
||||||
derivedField: int
|
derivedField: int
|
||||||
|
|
||||||
|
DerivedFromRefType = ref object of DerivedType
|
||||||
|
anotherDerivedField: string
|
||||||
|
|
||||||
macro getFieldsLists(T: type): untyped =
|
macro getFieldsLists(T: type): untyped =
|
||||||
result = newTree(nnkBracket)
|
result = newTree(nnkBracket)
|
||||||
|
|
||||||
|
@ -29,10 +32,11 @@ macro getFieldsLists(T: type): untyped =
|
||||||
result.add newLit($f.name)
|
result.add newLit($f.name)
|
||||||
|
|
||||||
static:
|
static:
|
||||||
doAssert getFieldsLists(DerivedType) == [
|
doAssert getFieldsLists(DerivedFromRefType) == [
|
||||||
"baseField",
|
"baseField",
|
||||||
"baseCaseField",
|
"baseCaseField",
|
||||||
"baseA",
|
"baseA",
|
||||||
"derivedField"
|
"derivedField",
|
||||||
|
"anotherDerivedField"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue