diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-03-06 15:57:39 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-03-06 15:57:46 +0100 |
commit | eeea00058247e09a81e802f541194389d673c627 (patch) | |
tree | 267ab8b0f76459395ca10652bbd40ae29b9849dd /compiler | |
parent | 077ff83b6e27dad47c654f6d732fb03618f07748 (diff) | |
download | Nim-eeea00058247e09a81e802f541194389d673c627.tar.gz |
make the 'canimport' template work
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/semexprs.nim | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index f1d226160..8e3aeffbe 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -2376,7 +2376,14 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = of nkMacroDef: result = semMacroDef(c, n) of nkTemplateDef: result = semTemplateDef(c, n) of nkImportStmt: - if not isTopLevel(c): localError(n.info, errXOnlyAtModuleScope, "import") + # this particular way allows 'import' in a 'compiles' context so that + # template canImport(x): bool = + # compiles: + # import x + # + # works: + if c.currentScope.depthLevel > 2 + c.compilesContextId: + localError(n.info, errXOnlyAtModuleScope, "import") result = evalImport(c, n) of nkImportExceptStmt: if not isTopLevel(c): localError(n.info, errXOnlyAtModuleScope, "import") |