Skip to content

Commit aa881f8

Browse files
committed
VM: allow var variables at CT
1 parent 9428916 commit aa881f8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

compiler/vmgen.nim

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,11 +1474,17 @@ proc getOwner(c: PCtx): PSym =
14741474
result = c.prc.sym
14751475
if result.isNil: result = c.module
14761476

1477+
proc importcCondVar*(s: PSym): bool {.inline.} =
1478+
# see also importcCond
1479+
if sfImportc in s.flags:
1480+
return s.kind in {skVar, skLet, skConst}
1481+
14771482
proc checkCanEval(c: PCtx; n: PNode) =
14781483
# we need to ensure that we don't evaluate 'x' here:
14791484
# proc foo() = var x ...
14801485
let s = n.sym
14811486
if {sfCompileTime, sfGlobal} <= s.flags: return
1487+
if s.importcCondVar: return
14821488
if s.kind in {skVar, skTemp, skLet, skParam, skResult} and
14831489
not s.isOwnedBy(c.prc.sym) and s.owner != c.module and c.mode != emRepl:
14841490
# little hack ahead for bug #12612: assume gensym'ed variables
@@ -1618,12 +1624,12 @@ proc genRdVar(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) =
16181624
assert card(flags * {gfNodeAddr, gfNode}) < 2
16191625
let s = n.sym
16201626
if s.isGlobal:
1621-
if sfCompileTime in s.flags or c.mode == emRepl:
1627+
if sfCompileTime in s.flags or c.mode == emRepl or importcCondVar(s):
16221628
discard
16231629
elif s.position == 0:
16241630
cannotEval(c, n)
16251631
if s.position == 0:
1626-
if importcCond(s): c.importcSym(n.info, s)
1632+
if importcCond(s) or importcCondVar(s): c.importcSym(n.info, s)
16271633
else: genGlobalInit(c, n, s)
16281634
if dest < 0: dest = c.getTemp(n.typ)
16291635
assert s.typ != nil

0 commit comments

Comments
 (0)