From 263d245cacbf461d6a64b7825185133935573916 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Thu, 13 Jun 2024 12:49:03 +0200 Subject: [PATCH] Work around Nim bug that erases type `{.pragma.}` when making alias Replaces `type` with inlined `template` because assigning to a new type drops pragma annotations in some situations. --- serialization/object_serialization.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/serialization/object_serialization.nim b/serialization/object_serialization.nim index 336b905..02b653c 100644 --- a/serialization/object_serialization.nim +++ b/serialization/object_serialization.nim @@ -104,7 +104,6 @@ macro enumAllSerializedFieldsImpl(T: type, body: untyped): untyped = continue let - fieldType = field.typ fieldIdent = field.name realFieldName = newLit($fieldIdent.skipPragma) serializedFieldName = field.readPragma("serializedFieldName") @@ -137,7 +136,9 @@ macro enumAllSerializedFieldsImpl(T: type, body: untyped): untyped = block: `fieldNameDefs` - type FieldType {.inject, used.} = type(`field`) + # `FieldType` should be `type`: + # https://github.com/nim-lang/Nim/issues/23564 + template FieldType: untyped {.inject, used.} = typeof(`field`) template fieldCaseDiscriminator: auto {.used.} = `discriminator` template fieldCaseBranches: auto {.used.} = `branches`