fixes #24258; compiler crash on len of varargs[untyped] (#24307)

fixes #24258

It uses conditionals to guard against ill formed AST to produce better
error messages, rather than crashing
This commit is contained in:
ringabout
2024-10-14 23:43:12 +08:00
committed by GitHub
parent 6df050d6d2
commit 8b39b2df7d
2 changed files with 14 additions and 3 deletions

View File

@@ -1311,10 +1311,11 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) =
put(g, tkCustomLit, n[0].strVal)
gsub(g, n, 1)
else:
gsub(g, n, 0)
for i in 0..<n.len-1:
gsub(g, n, i)
put(g, tkDot, ".")
assert n.len == 2, $n.len
accentedName(g, n[1])
if n.len > 1:
accentedName(g, n[^1])
of nkBind:
putWithSpace(g, tkBind, "bind")
gsub(g, n, 0)

10
tests/errmsgs/t24258.nim Normal file
View File

@@ -0,0 +1,10 @@
discard """
cmd: "nim check $file"
errormsg: "illformed AST: [22]43.len"
joinable: false
"""
template encodeList*(args: varargs[untyped]): seq[byte] =
@[byte args.len]
let x = encodeList([22], 43)