From 67707a54b5df274372fc8c43f1fe8887aa14870b Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sat, 13 Jun 2026 13:04:17 +0800 Subject: [PATCH] fixes #18367 and #21222; using quote inside static block (#25907) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #18367 fixes #21222 1. In vmdef.nim:304, newCtx now sets templInstCounter: new int when it builds TCtx. 2. vm.nim:1490 — During VM execution of templates, c.templInstCounter is passed to evalTemplate 3. evaltempl.nim:204 — instID: instID[] dereferences the ref int 4. With a nil templInstCounter, this would crash 5. The same initialization already exists on the semantic side in sem.nim:787, so this change makes the VM path consistent with the rest of the compiler. --- compiler/vmdef.nim | 2 +- tests/vm/tquote.nim | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/vm/tquote.nim diff --git a/compiler/vmdef.nim b/compiler/vmdef.nim index a3ac120f99..8310062dbb 100644 --- a/compiler/vmdef.nim +++ b/compiler/vmdef.nim @@ -308,7 +308,7 @@ proc newCtx*(module: PSym; cache: IdentCache; g: ModuleGraph; idgen: IdGenerator callDepth: g.config.maxCallDepthVM, comesFromHeuristic: unknownLineInfo, callbacks: @[], callbackIndex: initTable[string, int](), errorFlag: "", cache: cache, config: g.config, graph: g, idgen: idgen, - contstantTab: initNodeTable(true)) + contstantTab: initNodeTable(true), templInstCounter: new int) proc refresh*(c: PCtx, module: PSym; idgen: IdGenerator) = c.module = module diff --git a/tests/vm/tquote.nim b/tests/vm/tquote.nim new file mode 100644 index 0000000000..3b4c520519 --- /dev/null +++ b/tests/vm/tquote.nim @@ -0,0 +1,13 @@ +discard """ + joinable: false +""" + +import std/macros + +static: + discard quote: + a and b + +var x {.compileTime.} : NimNode = + quote do: + echo "xxx" \ No newline at end of file