Skip to content

Commit

Permalink
avoid implicit synthesis of CaseTransition (#59)
Browse files Browse the repository at this point in the history
Transitioning the case of a case object without full reinitialization
leads to undefined behaviour. Don't do such transitions implicitly,
and require explicit `readValue` override for such types in those cases.
  • Loading branch information
etan-status committed Jun 12, 2023
1 parent f0860e1 commit c23b499
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion serialization/object_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ proc makeFieldReadersTable(RecordType, ReaderType: distinct type,
when RecordType is tuple:
reader.readValue obj[i]
else:
static: doAssert not isCaseObject(typeof(obj)),
"Case object `" & $typeof(obj) &
"` must have custom `readValue` for `" & $typeof(reader) & "`"
type F = FieldTag[RecordType, realFieldName]
field(obj, realFieldName) = readFieldIMPL(F, reader)
except SerializationError as err:
Expand Down Expand Up @@ -419,4 +422,3 @@ macro useCustomSerialization*(Format: typed, field: untyped, body: untyped): unt

when defined(debugUseCustomSerialization):
echo result.repr

0 comments on commit c23b499

Please sign in to comment.