From bfd4b9b7a4935a4c5a8c7cc8adfea338afd03caf Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 20 Aug 2024 20:41:07 +0800 Subject: [PATCH] fixes #23945; type checking for whenvm expresssions (#23970) fixes #23945 (cherry picked from commit dda638c1ba985a77eac3c7518138992521884172) --- compiler/semexprs.nim | 2 ++ lib/pure/md5.nim | 19 +++---------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index c0edfa9d3b..80c5fd0840 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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) diff --git a/lib/pure/md5.nim b/lib/pure/md5.nim index c65a9c2daf..9c3f6d51b8 100644 --- a/lib/pure/md5.nim +++ b/lib/pure/md5.nim @@ -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)