mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 08:54:53 +00:00
This commit is contained in:
@@ -1911,6 +1911,8 @@ proc genVarSection(c: PCtx; n: PNode) =
|
||||
let s = a[0].sym
|
||||
checkCanEval(c, a[0])
|
||||
if s.isGlobal:
|
||||
let runtimeAccessToCompileTime = c.mode == emRepl and
|
||||
sfCompileTime in s.flags and s.position > 0
|
||||
if s.position == 0:
|
||||
if importcCond(c, s): c.importcSym(a.info, s)
|
||||
else:
|
||||
@@ -1920,7 +1922,9 @@ proc genVarSection(c: PCtx; n: PNode) =
|
||||
assert sa.kind != nkCall
|
||||
c.globals.add(sa)
|
||||
s.position = c.globals.len
|
||||
if a[2].kind != nkEmpty:
|
||||
if runtimeAccessToCompileTime:
|
||||
discard
|
||||
elif a[2].kind != nkEmpty:
|
||||
let tmp = c.genx(a[0], {gfNodeAddr})
|
||||
let val = c.genx(a[2])
|
||||
c.genAdditionalCopy(a[2], opcWrDeref, tmp, 0, val)
|
||||
|
||||
7
tests/vm/mscriptcompiletime.nim
Normal file
7
tests/vm/mscriptcompiletime.nim
Normal file
@@ -0,0 +1,7 @@
|
||||
# bug.nim
|
||||
var bar* {.compileTime.} = 1
|
||||
|
||||
proc dummy = discard
|
||||
|
||||
static:
|
||||
inc bar
|
||||
9
tests/vm/tscriptcompiletime.nims
Normal file
9
tests/vm/tscriptcompiletime.nims
Normal file
@@ -0,0 +1,9 @@
|
||||
discard """
|
||||
cmd: "nim e $file"
|
||||
"""
|
||||
|
||||
import mscriptcompiletime
|
||||
|
||||
macro foo =
|
||||
doAssert bar == 2
|
||||
foo()
|
||||
Reference in New Issue
Block a user