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

View File

@ -191,8 +191,14 @@ proc recordFields*(typeImpl: NimNode): seq[FieldDescription] =
result.add FieldDescription(typ: typeImpl[i], name: ident("Field" & $(i - 1))) result.add FieldDescription(typ: typeImpl[i], name: ident("Field" & $(i - 1)))
return return
typeImpl.expectKind nnkTypeDef let objectType = case typeImpl.kind
collectFieldsInHierarchy(result, typeImpl[2]) 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 = macro field*(obj: typed, fieldName: static string): untyped =
newDotExpr(obj, ident fieldName) newDotExpr(obj, ident fieldName)