Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #23945; type checking for whenvm expresssions #23970

Merged
merged 7 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2684,6 +2684,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)
Expand All @@ -2694,6 +2696,11 @@ proc semWhen(c: PContext, n: PNode, semCheck = true): PNode =
if n.len == 1:
result.add(newTree(nkElse, newNode(nkStmtList)))

if $result.typ == "seq[uint8]":
echo " -> ", result.typ
echo semCheck
echo n.renderTree

ringabout marked this conversation as resolved.
Show resolved Hide resolved
proc semSetConstr(c: PContext, n: PNode, expectedType: PType = nil): PNode =
result = newNodeI(nkCurly, n.info)
result.typ = newTypeS(tySet, c)
Expand Down
19 changes: 3 additions & 16 deletions lib/pure/md5.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading