mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
Ping @narimiran please backport to the 2.0 line.
(cherry picked from commit 6c4e7835bf)
This commit is contained in:
@@ -200,7 +200,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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user