@@ -226,33 +226,27 @@ proc readRecordValue*[T](r: var JsonReader, value: var T)
226226 r.raiseUnexpectedField (key, cstring typeName)
227227
228228template autoSerializeCheck (F: distinct type , T: distinct type , body) =
229- when declared (macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey
230- mixin typeAutoSerialize
231- when not F.typeAutoSerialize (T):
232- const
233- typeName = typetraits.name (T)
234- flavorName = typetraits.name (F)
235- {.error : flavorName &
236- " : automatic serialization is not enabled or readValue not implemented for `" &
237- typeName & " `" .}
238- else :
239- body
229+ mixin typeAutoSerialize
230+ when not F.typeAutoSerialize (T):
231+ const
232+ typeName = typetraits.name (T)
233+ flavorName = typetraits.name (F)
234+ {.error : flavorName &
235+ " : automatic serialization is not enabled or readValue not implemented for `" &
236+ typeName & " `" .}
240237 else :
241238 body
242239
243240template autoSerializeCheck (F: distinct type , TC: distinct type , M: distinct type , body) =
244- when declared (macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey
245- mixin typeClassOrMemberAutoSerialize
246- when not F.typeClassOrMemberAutoSerialize (TC , M):
247- const
248- typeName = typetraits.name (M)
249- typeClassName = typetraits.name (TC )
250- flavorName = typetraits.name (F)
251- {.error : flavorName &
252- " : automatic serialization is not enabled or readValue not implemented for `" &
253- typeName & " ` of typeclass `" & typeClassName & " `" .}
254- else :
255- body
241+ mixin typeClassOrMemberAutoSerialize
242+ when not F.typeClassOrMemberAutoSerialize (TC , M):
243+ const
244+ typeName = typetraits.name (M)
245+ typeClassName = typetraits.name (TC )
246+ flavorName = typetraits.name (F)
247+ {.error : flavorName &
248+ " : automatic serialization is not enabled or readValue not implemented for `" &
249+ typeName & " ` of typeclass `" & typeClassName & " `" .}
256250 else :
257251 body
258252
@@ -391,17 +385,11 @@ proc readValue*[T](r: var JsonReader, value: var T)
391385 r.raiseUnexpectedValue (" Too many items for " & $ (typeof (value)))
392386
393387 elif value is object :
394- when declared (macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey and cannot accept `object` param
395- autoSerializeCheck (Flavor , object , typeof (value)):
396- readValueObjectOrTuple (Flavor , r, value)
397- else :
388+ autoSerializeCheck (Flavor , object , typeof (value)):
398389 readValueObjectOrTuple (Flavor , r, value)
399390
400391 elif value is tuple :
401- when declared (macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey and cannot accept `tuple` param
402- autoSerializeCheck (Flavor , tuple , typeof (value)):
403- readValueObjectOrTuple (Flavor , r, value)
404- else :
392+ autoSerializeCheck (Flavor , tuple , typeof (value)):
405393 readValueObjectOrTuple (Flavor , r, value)
406394
407395 else :
0 commit comments