From e126d48e6cdf032ad34a10bb5651003afe80ed78 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Wed, 10 Jul 2019 20:18:12 +0300 Subject: [PATCH] Use the new fixed hasCustomPragma definition --- serialization/object_serialization.nim | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/serialization/object_serialization.nim b/serialization/object_serialization.nim index 51c411a..ea3da2e 100644 --- a/serialization/object_serialization.nim +++ b/serialization/object_serialization.nim @@ -24,8 +24,10 @@ template enumInstanceSerializedFields*(obj: auto, ## will be read first and the iteration will continue depending on the ## value being deserialized. ## + type ObjType = type(obj) + for fieldNameVar, fieldVar in fieldPairs(obj): - when not hasCustomPragma(fieldVar, dontSerialize): + when not hasCustomPragmaFixed(ObjType, fieldNameVar, dontSerialize): body macro enumAllSerializedFields*(T: type, @@ -46,21 +48,24 @@ macro enumAllSerializedFields*(T: type, ## a different order. Fields marked with the `dontSerialize` pragma ## are skipped. ## - var T = getImpl(getType(T)[1]) + var Timpl = getImpl(getType(T)[1]) result = newStmtList() - for field in recordFields(T): + for field in recordFields(Timpl): if field.readPragma("dontSerialize") != nil: continue let + fident = field.name fieldName = newLit($field.name) fieldType = field.typ result.add quote do: block: template `fieldNameVar`: auto = `fieldName` - type `fieldTypeVar` = `fieldType` + # type `fieldTypeVar` = `fieldType` + # TODO: This is a work-around for a classic Nim issue: + type `fieldTypeVar` = type(default(`T`).`fident`) `body` type