When in object handles procedure call again, fixes #22474 (#22480)

Ping @narimiran please backport to the 2.0 line.

(cherry picked from commit 6c4e7835bf)
This commit is contained in:
Jason Beetham
2023-08-15 09:48:31 -06:00
committed by narimiran
parent ba5d873f63
commit 60dc41a5e4
2 changed files with 33 additions and 1 deletions

View File

@@ -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:

View File

@@ -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