From 4a3e94702ee9593210ce2c9d7c6b471931820f33 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Wed, 20 Oct 2021 17:37:14 +0200 Subject: [PATCH] allow `ElemType(XXX)` on inputs not called `T` Currently, `ElemType` can only be called on `HashArray`, `HashList` and `List` types when they are first assigned to a variable called `T`. The templates have been adjusted so that different variable names may be used. The templates can now also be applied to in-line computed types, e.g., `ElemType(typeof(x))`. --- beacon_chain/ssz/types.nim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/beacon_chain/ssz/types.nim b/beacon_chain/ssz/types.nim index e454504f1..aa6c0dd34 100644 --- a/beacon_chain/ssz/types.nim +++ b/beacon_chain/ssz/types.nim @@ -397,11 +397,11 @@ macro unsupported*(T: typed): untyped = else: error "SSZ serialization of the type " & humaneTypeName(T) & " is not supported, overload toSszType and fromSszBytes" -template ElemType*(T: type HashArray): untyped = - T.T +template ElemType*(T0: type HashArray): untyped = + T0.T -template ElemType*(T: type HashList): untyped = - T.T +template ElemType*(T0: type HashList): untyped = + T0.T template ElemType*(T: type array): untyped = type(default(T)[low(T)]) @@ -409,8 +409,8 @@ template ElemType*(T: type array): untyped = template ElemType*(T: type seq): untyped = type(default(T)[0]) -template ElemType*(T: type List): untyped = - T.T +template ElemType*(T0: type List): untyped = + T0.T func isFixedSize*(T0: type): bool {.compileTime.} = mixin toSszType, enumAllSerializedFields