avoid implicit synthesis of `CaseTransition` (#59)

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.
This commit is contained in:
Etan Kissling 2023-06-12 23:17:15 +02:00 committed by GitHub
parent f0860e1c25
commit c23b49910d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -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:
@ -419,4 +422,3 @@ macro useCustomSerialization*(Format: typed, field: untyped, body: untyped): unt
when defined(debugUseCustomSerialization):
echo result.repr