Skip to content

Commit 76d834c

Browse files
ringaboutnarimiran
authored andcommitted
fixes nim-lang#24258; compiler crash on len of varargs[untyped] (nim-lang#24307)
fixes nim-lang#24258 It uses conditionals to guard against ill formed AST to produce better error messages, rather than crashing (cherry picked from commit 8b39b2d)
1 parent 72fcda1 commit 76d834c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

compiler/renderer.nim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,10 +1310,11 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) =
13101310
put(g, tkCustomLit, n[0].strVal)
13111311
gsub(g, n, 1)
13121312
else:
1313-
gsub(g, n, 0)
1313+
for i in 0..<n.len-1:
1314+
gsub(g, n, i)
13141315
put(g, tkDot, ".")
1315-
assert n.len == 2, $n.len
1316-
accentedName(g, n[1])
1316+
if n.len > 1:
1317+
accentedName(g, n[^1])
13171318
of nkBind:
13181319
putWithSpace(g, tkBind, "bind")
13191320
gsub(g, n, 0)

tests/errmsgs/t24258.nim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
discard """
2+
cmd: "nim check $file"
3+
errormsg: "illformed AST: [22]43.len"
4+
joinable: false
5+
"""
6+
7+
template encodeList*(args: varargs[untyped]): seq[byte] =
8+
@[byte args.len]
9+
10+
let x = encodeList([22], 43)

0 commit comments

Comments
 (0)