fixes #23945; type checking for whenvm expresssions (#23970)

fixes #23945

(cherry picked from commit dda638c1ba)
This commit is contained in:
ringabout
2024-08-20 20:41:07 +08:00
committed by narimiran
parent 7d2fe8086f
commit bfd4b9b7a4
2 changed files with 5 additions and 16 deletions

View File

@@ -2685,6 +2685,8 @@ proc semWhen(c: PContext, n: PNode, semCheck = true): PNode =
if semCheck:
it[0] = semExpr(c, it[0], flags)
typ = commonType(c, typ, it[0].typ)
if typ != nil and typ.kind != tyUntyped:
it[0] = fitNode(c, typ, it[0], it[0].info)
if result == nil:
result = it[0]
else: illFormedAst(n, c.config)

View File

@@ -100,32 +100,19 @@ proc decode(dest: var openArray[uint8], src: openArray[uint32]) =
dest[i+3] = uint8(src[j] shr 24 and 0xff'u32)
inc(i, 4)
template slice(s: string, a, b): openArray[uint8] =
when nimvm:
# toOpenArray is not implemented in VM
var s2 = newSeq[uint8](s.len)
for i in 0 ..< s2.len:
s2[i] = uint8(s[i])
s2
else:
s.toOpenArrayByte(a, b)
template slice(s: cstring, a, b): openArray[uint8] =
when nimvm:
# toOpenArray is not implemented in VM
slice($s, a, b)
toOpenArrayByte($s, a, b)
else:
when defined(js):
# toOpenArrayByte for cstring is not implemented in JS
slice($s, a, b)
toOpenArrayByte($s, a, b)
else:
s.toOpenArrayByte(a, b)
template slice(s: openArray[uint8], a, b): openArray[uint8] =
when nimvm:
s[a .. b]
else:
s.toOpenArray(a, b)
s.toOpenArray(a, b)
const useMem = declared(copyMem)