summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-03-13 03:03:46 +0800
committerGitHub <noreply@github.com>2023-03-12 20:03:46 +0100
commitb2c1dcbbc9b097c9c13dda4951e824cdb5f16225 (patch)
treeab1dc0d39f6da34bd006668793a474a1391e8a08
parentffadc75afead6baed0885877edb2c3b1c9ef1b2e (diff)
downloadNim-b2c1dcbbc9b097c9c13dda4951e824cdb5f16225.tar.gz
fixes explicit globals in macros (#21502)
-rw-r--r--compiler/vmgen.nim3
-rw-r--r--tests/vm/tvmmisc.nim13
2 files changed, 15 insertions, 1 deletions
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim
index be7938e53..937d4b095 100644
--- a/compiler/vmgen.nim
+++ b/compiler/vmgen.nim
@@ -1909,7 +1909,8 @@ proc genVarSection(c: PCtx; n: PNode) =
           c.genAdditionalCopy(a[2], opcWrDeref, tmp, 0, val)
           c.freeTemp(val)
           c.freeTemp(tmp)
-        elif not importcCondVar(s) and not (s.typ.kind == tyProc and s.typ.callConv == ccClosure): # fixes #10938
+        elif not importcCondVar(s) and not (s.typ.kind == tyProc and s.typ.callConv == ccClosure) and
+                sfPure notin s.flags: # fixes #10938
           # there is a pre-existing issue with closure types in VM
           # if `(var s: proc () = default(proc ()); doAssert s == nil)` works for you;
           # you might remove the second condition.
diff --git a/tests/vm/tvmmisc.nim b/tests/vm/tvmmisc.nim
index 673e3e965..14818375d 100644
--- a/tests/vm/tvmmisc.nim
+++ b/tests/vm/tvmmisc.nim
@@ -643,3 +643,16 @@ const b = block:
 
 doAssert a == @[@[0, 1, 2], @[0, 1, 2], @[0, 1, 2]]
 doAssert b == @[@[0, 1, 2], @[0, 1, 2], @[0, 1, 2]]
+
+macro m1(s: string): int =
+  var ProcID {.global, compileTime.}: int
+  inc(ProcID)
+  result = newLit(ProcID)
+
+proc macroGlobal =
+  doAssert m1("Macro argument") == 1
+  doAssert m1("Macro argument") == 2
+  doAssert m1("Macro argument") == 3
+
+static: macroGlobal()
+macroGlobal()