From 6e01be34efd60869c7905b1effcc47880cedfb6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20D=C3=B6ring?= Date: Sat, 31 Aug 2019 19:32:59 +0200 Subject: [PATCH] fixes #11903 (#11908) --- compiler/vm.nim | 4 +++- tests/tools/tnimscriptwithmacro.nims | 22 ++++++++++++++++++++++ tests/vm/tgloballetfrommacro.nim | 13 +++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/tools/tnimscriptwithmacro.nims create mode 100644 tests/vm/tgloballetfrommacro.nim diff --git a/compiler/vm.nim b/compiler/vm.nim index 31dec418fd..072a1826b1 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -2102,8 +2102,9 @@ proc evalMacroCall*(module: PSym; g: ModuleGraph; setupGlobalCtx(module, g) var c = PCtx g.vm + let oldMode = c.mode + c.mode = emStaticStmt c.comesFromHeuristic.line = 0'u16 - c.callsite = nOrig let start = genProc(c, sym) @@ -2142,3 +2143,4 @@ proc evalMacroCall*(module: PSym; g: ModuleGraph; if cyclicTree(result): globalError(c.config, n.info, "macro produced a cyclic tree") dec(g.config.evalMacroCounter) c.callsite = nil + c.mode = oldMode diff --git a/tests/tools/tnimscriptwithmacro.nims b/tests/tools/tnimscriptwithmacro.nims new file mode 100644 index 0000000000..8b97f07696 --- /dev/null +++ b/tests/tools/tnimscriptwithmacro.nims @@ -0,0 +1,22 @@ +discard """ +cmd: "nim e $file" +output: ''' +foobar +nothing +hallo +""" + +# this test ensures that the mode is resetted correctly to repr + +import macros + +macro foobar(): void = + result = newCall(bindSym"echo", newLit("nothing")) + +echo "foobar" + +let x = 123 + +foobar() + +exec "echo hallo" diff --git a/tests/vm/tgloballetfrommacro.nim b/tests/vm/tgloballetfrommacro.nim new file mode 100644 index 0000000000..14dbff1e83 --- /dev/null +++ b/tests/vm/tgloballetfrommacro.nim @@ -0,0 +1,13 @@ +discard """ +errormsg: "cannot evaluate at compile time: BUILTIN_NAMES" +line: 11 +""" + +import sets + +let BUILTIN_NAMES = toSet(["int8", "int16", "int32", "int64"]) + +macro test*(): bool = + echo "int64" notin BUILTIN_NAMES + +echo test()