diff --git a/compiler/front/scripting.nim b/compiler/front/scripting.nim index cb837bb09e7..7f80aaf5723 100644 --- a/compiler/front/scripting.nim +++ b/compiler/front/scripting.nim @@ -199,7 +199,10 @@ proc runNimScript*(cache: IdentCache; scriptName: AbsoluteFile; var m = graph.makeModule(scriptName) incl(m.flags, sfMainModule) - var vm = setupVM(m, cache, scriptName.string, graph, graph.idgen) + # use a dedicated ID generator for the module; don't reuse the graph's + let idgen = idGeneratorFromModule(m) + + var vm = setupVM(m, cache, scriptName.string, graph, idgen) let disallowDanger = defined(nimsuggest) or graph.config.cmd == cmdCheck or vmopsDanger notin graph.config.features @@ -217,6 +220,6 @@ proc runNimScript*(cache: IdentCache; scriptName: AbsoluteFile; graph.vm = PEvalContext(vm: vm) graph.compileSystemModule() - discard graph.processModule(m, graph.idgen, stream) + discard graph.processModule(m, idgen, stream) undefSymbol(conf, "nimscript") diff --git a/tests/test_nimscript.nims b/tests/test_nimscript.nims index d70a371dbf6..1a20d95b043 100644 --- a/tests/test_nimscript.nims +++ b/tests/test_nimscript.nims @@ -88,6 +88,11 @@ import stdlib/os/tosenv echo "Nimscript imports are successful." +block: + # a procedure with a .header (or .dynlib) pragma defined directly inside + # the executed NimScript file would crash the compiler + proc test() {.importc, header: "ignore".} + block: doAssert "./foo//./bar/".normalizedPath == "foo/bar".unixToNativePath block: