diff options
-rw-r--r-- | compiler/semtypinst.nim | 2 | ||||
-rw-r--r-- | tests/objects/twhen1.nim | 32 |
2 files changed, 33 insertions, 1 deletions
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index 56b922fda..d01ca28e4 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -204,7 +204,7 @@ proc hasValuelessStatics(n: PNode): bool = a proc doThing(_: MyThing) ]# - if n.safeLen == 0: + if n.safeLen == 0 and n.kind != nkEmpty: # Some empty nodes can get in here n.typ == nil or n.typ.kind == tyStatic else: for x in n: diff --git a/tests/objects/twhen1.nim b/tests/objects/twhen1.nim index 5b8eea3f4..fe072a46b 100644 --- a/tests/objects/twhen1.nim +++ b/tests/objects/twhen1.nim @@ -55,3 +55,35 @@ type x: int when (NimMajor, NimMinor) >= (1, 1): y: int +discard MyObject(x: 100, y: 200) + +block: # Ensure when evaluates properly in objects + type X[bits: static int] = object #22474 + when bits >= 256: + data32: byte + else: + data16: byte + + static: + discard X[255]().data16 + discard X[256]().data32 + + + type ComplexExprObject[S: static string, I: static int, Y: static auto] = object + when 'h' in S and I < 10 and Y isnot float: + a: int + elif I > 30: + b: int + elif typeof(Y) is float: + c: int + else: + d: int + + static: + discard ComplexExprObject["hello", 9, 300i32]().a + discard ComplexExprObject["", 40, 30f]().b + discard ComplexExprObject["", 20, float 30]().c + discard ComplexExprObject["", 20, ""]().d + + + |