From 4d170ac58657a60316cc606dd3e5e621cb075be7 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Mon, 14 Oct 2024 23:43:12 +0800 Subject: [PATCH] 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 (cherry picked from commit 8b39b2df7d638344a8df918486b94f6fde572494) --- compiler/renderer.nim | 7 ++++--- tests/errmsgs/t24258.nim | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 tests/errmsgs/t24258.nim diff --git a/compiler/renderer.nim b/compiler/renderer.nim index cc07c0c2d5..a598a0ae5e 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -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.. 1: + accentedName(g, n[^1]) of nkBind: putWithSpace(g, tkBind, "bind") gsub(g, n, 0) diff --git a/tests/errmsgs/t24258.nim b/tests/errmsgs/t24258.nim new file mode 100644 index 0000000000..17466d4b2d --- /dev/null +++ b/tests/errmsgs/t24258.nim @@ -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) \ No newline at end of file