From c23b49910db2dc20db9e731ec6421531b9379aaf Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Mon, 12 Jun 2023 23:17:15 +0200 Subject: [PATCH] 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. --- serialization/object_serialization.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/serialization/object_serialization.nim b/serialization/object_serialization.nim index 0c2a018..f06ddba 100644 --- a/serialization/object_serialization.nim +++ b/serialization/object_serialization.nim @@ -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 -