Revert "Support when statements in records that reuse the same field name in different branches"
This reverts commit 4e2ffe3f6d
.
This commit is contained in:
parent
293a987c51
commit
32fce5df8d
|
@ -101,7 +101,6 @@ macro enumAllSerializedFieldsImpl(T: type, body: untyped): untyped =
|
|||
|
||||
let
|
||||
fieldType = field.typ
|
||||
FieldTypeSym = getTypeInst(fieldType)
|
||||
fieldIdent = field.name
|
||||
realFieldName = newLit($fieldIdent.skipPragma)
|
||||
serializedFieldName = field.readPragma("serializedFieldName")
|
||||
|
@ -133,15 +132,14 @@ macro enumAllSerializedFieldsImpl(T: type, body: untyped): untyped =
|
|||
result.add quote do:
|
||||
block:
|
||||
when compiles(type(`field`)):
|
||||
`fieldNameDefs`
|
||||
|
||||
type FieldType {.inject, used.} = type(`field`)
|
||||
|
||||
when FieldType is `FieldTypeSym`:
|
||||
`fieldNameDefs`
|
||||
template fieldCaseDiscriminator: auto {.used.} = `discriminator`
|
||||
template fieldCaseBranches: auto {.used.} = `branches`
|
||||
|
||||
template fieldCaseDiscriminator: auto {.used.} = `discriminator`
|
||||
template fieldCaseBranches: auto {.used.} = `branches`
|
||||
|
||||
`body`
|
||||
`body`
|
||||
|
||||
i += 1
|
||||
|
||||
|
|
|
@ -4,41 +4,19 @@ import
|
|||
../serialization/object_serialization,
|
||||
../serialization/testing/generic_suite
|
||||
|
||||
type
|
||||
Untrusted = object
|
||||
Trusted = object
|
||||
|
||||
Signature = object
|
||||
p: int
|
||||
k: float
|
||||
|
||||
TrustedSignature = object
|
||||
data: string
|
||||
|
||||
SignatureHolder[TrustLevel] = object
|
||||
when TrustLevel is Trusted:
|
||||
sig: TrustedSignature
|
||||
origin: string
|
||||
else:
|
||||
sig: Signature
|
||||
|
||||
func collectFields(T: type): seq[string] =
|
||||
enumAllSerializedFields(T):
|
||||
result.add(name(FieldType) & " " & fieldName & fieldCaseDiscriminator)
|
||||
|
||||
suite "object serialization":
|
||||
test "custom fields order":
|
||||
check collectFields(Simple) == @["Meter distance", "int x", "string y"]
|
||||
|
||||
test "tuples handling":
|
||||
setup:
|
||||
var fieldsList = newSeq[string]()
|
||||
|
||||
test "custom fields order":
|
||||
enumAllSerializedFields(Simple):
|
||||
fieldsList.add(name(FieldType) & " " & fieldName & fieldCaseDiscriminator)
|
||||
|
||||
check fieldsList == @["Meter distance", "int x", "string y"]
|
||||
|
||||
test "tuples handling":
|
||||
enumAllSerializedFields(HoldsTuples):
|
||||
fieldsList.add(fieldName & ": " & $isTuple(FieldType))
|
||||
|
||||
check fieldsList == @["t1: true", "t2: true", "t3: true"]
|
||||
|
||||
test "when statements":
|
||||
check collectFields(SignatureHolder[Trusted]) == @["TrustedSignature sig", "string origin"]
|
||||
check collectFields(SignatureHolder[Untrusted]) == @["Signature sig"]
|
||||
|
||||
|
|
Loading…
Reference in New Issue