Skip to content

Commit

Permalink
Work around Nim bug that erases type {.pragma.} when making alias
Browse files Browse the repository at this point in the history
Replaces `type` with inlined `template` because assigning to a new type
drops pragma annotations in some situations.
  • Loading branch information
etan-status committed Jun 13, 2024
1 parent afae13a commit 263d245
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions serialization/object_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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`
Expand Down

0 comments on commit 263d245

Please sign in to comment.