Merge pull request #1574 from trustable-code/PR3
Do not allow self import
This commit is contained in:
commit
b29c0da7b5
2 changed files with 12 additions and 2 deletions
|
|
@ -92,7 +92,7 @@ proc rawImportSymbol(c: PContext, s: PSym) =
|
||||||
if s.kind == skConverter: addConverter(c, s)
|
if s.kind == skConverter: addConverter(c, s)
|
||||||
if hasPattern(s): addPattern(c, s)
|
if hasPattern(s): addPattern(c, s)
|
||||||
|
|
||||||
proc importSymbol(c: PContext, n: PNode, fromMod: PSym) =
|
proc importSymbol(c: PContext, n: PNode, fromMod: PSym) =
|
||||||
let ident = lookups.considerQuotedIdent(n)
|
let ident = lookups.considerQuotedIdent(n)
|
||||||
let s = strTableGet(fromMod.tab, ident)
|
let s = strTableGet(fromMod.tab, ident)
|
||||||
if s == nil:
|
if s == nil:
|
||||||
|
|
@ -155,10 +155,12 @@ proc importModuleAs(n: PNode, realModule: PSym): PSym =
|
||||||
# some misguided guy will write 'import abc.foo as foo' ...
|
# some misguided guy will write 'import abc.foo as foo' ...
|
||||||
result = createModuleAlias(realModule, n.sons[1].ident, n.sons[1].info)
|
result = createModuleAlias(realModule, n.sons[1].ident, n.sons[1].info)
|
||||||
|
|
||||||
proc myImportModule(c: PContext, n: PNode): PSym =
|
proc myImportModule(c: PContext, n: PNode): PSym =
|
||||||
var f = checkModuleName(n)
|
var f = checkModuleName(n)
|
||||||
if f != InvalidFileIDX:
|
if f != InvalidFileIDX:
|
||||||
result = importModuleAs(n, gImportModule(c.module, f))
|
result = importModuleAs(n, gImportModule(c.module, f))
|
||||||
|
if result.info.fileIndex == n.info.fileIndex:
|
||||||
|
localError(n.info, errGenerated, "A module cannot import itself")
|
||||||
if sfDeprecated in result.flags:
|
if sfDeprecated in result.flags:
|
||||||
message(n.info, warnDeprecated, result.name.s)
|
message(n.info, warnDeprecated, result.name.s)
|
||||||
|
|
||||||
|
|
|
||||||
8
tests/modules/tselfimport.nim
Normal file
8
tests/modules/tselfimport.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
discard """
|
||||||
|
file: "tselfimport.nim"
|
||||||
|
line: 6
|
||||||
|
errormsg: "A module cannot import itself"
|
||||||
|
"""
|
||||||
|
import tselfimport #ERROR
|
||||||
|
echo("Hello World")
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue