summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2019-05-10 19:50:11 +0200
committerAraq <rumpf_a@web.de>2019-05-10 19:50:23 +0200
commitf03391d4775bffb3f51c9be47baf04f8b49e2900 (patch)
tree968788e58c21de01101a74fa80f17f8feb36ee4b /compiler
parent95b65504e6dfb598b0b2ffb13ecc6f219ab90697 (diff)
downloadNim-f03391d4775bffb3f51c9be47baf04f8b49e2900.tar.gz
fixes #6855
Diffstat (limited to 'compiler')
-rw-r--r--compiler/vmgen.nim11
1 files changed, 7 insertions, 4 deletions
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim
index 5bb44785a..9d9260563 100644
--- a/compiler/vmgen.nim
+++ b/compiler/vmgen.nim
@@ -1575,6 +1575,9 @@ proc genTypeLit(c: PCtx; t: PType; dest: var TDest) =
   n.typ = t
   genLit(c, n, dest)
 
+proc importcCond(s: PSym): bool {.inline.} =
+  sfImportc in s.flags and (lfDynamicLib notin s.loc.flags or s.ast == nil)
+
 proc importcSym(c: PCtx; info: TLineInfo; s: PSym) =
   when hasFFI:
     if compiletimeFFI in c.config.features:
@@ -1584,7 +1587,7 @@ proc importcSym(c: PCtx; info: TLineInfo; s: PSym) =
       localError(c.config, info, "VM is not allowed to 'importc'")
   else:
     localError(c.config, info,
-               "cannot 'importc' variable at compile time")
+               "cannot 'importc' variable at compile time; " & s.name.s)
 
 proc getNullValue*(typ: PType, info: TLineInfo; conf: ConfigRef): PNode
 
@@ -1612,7 +1615,7 @@ proc genRdVar(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) =
     elif s.position == 0:
       cannotEval(c, n)
     if s.position == 0:
-      if sfImportc in s.flags: c.importcSym(n.info, s)
+      if importcCond(s): c.importcSym(n.info, s)
       else: genGlobalInit(c, n, s)
     if dest < 0: dest = c.getTemp(n.typ)
     assert s.typ != nil
@@ -1815,7 +1818,7 @@ proc genVarSection(c: PCtx; n: PNode) =
       checkCanEval(c, a.sons[0])
       if s.isGlobal:
         if s.position == 0:
-          if sfImportc in s.flags: c.importcSym(a.info, s)
+          if importcCond(s): c.importcSym(a.info, s)
           else:
             let sa = getNullValue(s.typ, a.info, c.config)
             #if s.ast.isNil: getNullValue(s.typ, a.info)
@@ -1972,7 +1975,7 @@ proc gen(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags = {}) =
     of skProc, skFunc, skConverter, skMacro, skTemplate, skMethod, skIterator:
       # 'skTemplate' is only allowed for 'getAst' support:
       if procIsCallback(c, s): discard
-      elif sfImportc in s.flags: c.importcSym(n.info, s)
+      elif importcCond(s): c.importcSym(n.info, s)
       genLit(c, n, dest)
     of skConst:
       let constVal = if s.ast != nil: s.ast else: s.typ.n