More forgiving recordFields

This commit is contained in:
Zahary Karadjov 2022-07-28 19:50:32 +03:00
parent 2ab76e2cc2
commit 06621a2fcd
No known key found for this signature in database
GPG Key ID: C1F42EAFF38D570F
1 changed files with 8 additions and 2 deletions

View File

@ -191,8 +191,14 @@ proc recordFields*(typeImpl: NimNode): seq[FieldDescription] =
result.add FieldDescription(typ: typeImpl[i], name: ident("Field" & $(i - 1)))
return
typeImpl.expectKind nnkTypeDef
collectFieldsInHierarchy(result, typeImpl[2])
let objectType = case typeImpl.kind
of nnkObjectTy: typeImpl
of nnkTypeDef: typeImpl[2]
else:
macros.error("object type expected", typeImpl)
return
collectFieldsInHierarchy(result, objectType)
macro field*(obj: typed, fieldName: static string): untyped =
newDotExpr(obj, ident fieldName)