Work around Nim bug that erases type `{.pragma.}` when making alias (#71)

Replaces `type` with inlined `template` because assigning to a new type
drops pragma annotations in some situations.
This commit is contained in:
Etan Kissling 2024-06-13 13:34:04 +02:00 committed by GitHub
parent afae13adac
commit 005ee90cb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 2 deletions

View File

@ -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`