Locate 'attempt to redefine' errors at the import statement rather than at the first line of the imported module. Fixes #4541.
This commit is contained in:
parent
2605c8c4ce
commit
2bea2bdbbf
2 changed files with 7 additions and 3 deletions
|
|
@ -176,7 +176,7 @@ proc evalImport(c: PContext, n: PNode): PNode =
|
||||||
var m = myImportModule(c, n.sons[i])
|
var m = myImportModule(c, n.sons[i])
|
||||||
if m != nil:
|
if m != nil:
|
||||||
# ``addDecl`` needs to be done before ``importAllSymbols``!
|
# ``addDecl`` needs to be done before ``importAllSymbols``!
|
||||||
addDecl(c, m) # add symbol to symbol table of module
|
addDecl(c, m, n.info) # add symbol to symbol table of module
|
||||||
importAllSymbolsExcept(c, m, emptySet)
|
importAllSymbolsExcept(c, m, emptySet)
|
||||||
#importForwarded(c, m.ast, emptySet)
|
#importForwarded(c, m.ast, emptySet)
|
||||||
|
|
||||||
|
|
@ -186,7 +186,7 @@ proc evalFrom(c: PContext, n: PNode): PNode =
|
||||||
var m = myImportModule(c, n.sons[0])
|
var m = myImportModule(c, n.sons[0])
|
||||||
if m != nil:
|
if m != nil:
|
||||||
n.sons[0] = newSymNode(m)
|
n.sons[0] = newSymNode(m)
|
||||||
addDecl(c, m) # add symbol to symbol table of module
|
addDecl(c, m, n.info) # add symbol to symbol table of module
|
||||||
for i in countup(1, sonsLen(n) - 1):
|
for i in countup(1, sonsLen(n) - 1):
|
||||||
if n.sons[i].kind != nkNilLit:
|
if n.sons[i].kind != nkNilLit:
|
||||||
importSymbol(c, n.sons[i], m)
|
importSymbol(c, n.sons[i], m)
|
||||||
|
|
@ -197,7 +197,7 @@ proc evalImportExcept*(c: PContext, n: PNode): PNode =
|
||||||
var m = myImportModule(c, n.sons[0])
|
var m = myImportModule(c, n.sons[0])
|
||||||
if m != nil:
|
if m != nil:
|
||||||
n.sons[0] = newSymNode(m)
|
n.sons[0] = newSymNode(m)
|
||||||
addDecl(c, m) # add symbol to symbol table of module
|
addDecl(c, m, n.info) # add symbol to symbol table of module
|
||||||
var exceptSet = initIntSet()
|
var exceptSet = initIntSet()
|
||||||
for i in countup(1, sonsLen(n) - 1):
|
for i in countup(1, sonsLen(n) - 1):
|
||||||
let ident = lookups.considerQuotedIdent(n.sons[i])
|
let ident = lookups.considerQuotedIdent(n.sons[i])
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,10 @@ proc wrongRedefinition*(info: TLineInfo, s: string) =
|
||||||
if gCmd != cmdInteractive:
|
if gCmd != cmdInteractive:
|
||||||
localError(info, errAttemptToRedefine, s)
|
localError(info, errAttemptToRedefine, s)
|
||||||
|
|
||||||
|
proc addDecl*(c: PContext, sym: PSym, info: TLineInfo) =
|
||||||
|
if not c.currentScope.addUniqueSym(sym):
|
||||||
|
wrongRedefinition(info, sym.name.s)
|
||||||
|
|
||||||
proc addDecl*(c: PContext, sym: PSym) =
|
proc addDecl*(c: PContext, sym: PSym) =
|
||||||
if not c.currentScope.addUniqueSym(sym):
|
if not c.currentScope.addUniqueSym(sym):
|
||||||
wrongRedefinition(sym.info, sym.name.s)
|
wrongRedefinition(sym.info, sym.name.s)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue