diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-09-17 19:54:49 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-09-17 19:54:56 +0200 |
commit | 539fc5d58b77d43c19d10a3949841c26dcd2cffc (patch) | |
tree | c4069fdcc1dbb389de176e52517ba120a775ab44 /compiler/lookups.nim | |
parent | 3467c455c0a90a9f507e92b72cb7dd1a9aaf85e8 (diff) | |
download | Nim-539fc5d58b77d43c19d10a3949841c26dcd2cffc.tar.gz |
improve the error message for 'attempt to redefine X'; fixes #447
Diffstat (limited to 'compiler/lookups.nim')
-rw-r--r-- | compiler/lookups.nim | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/compiler/lookups.nim b/compiler/lookups.nim index ec9c130e3..d2e7fdcfa 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -58,8 +58,8 @@ proc considerQuotedIdent*(c: PContext; n: PNode, origin: PNode = nil): PIdent = template addSym*(scope: PScope, s: PSym) = strTableAdd(scope.symbols, s) -proc addUniqueSym*(scope: PScope, s: PSym): bool = - result = not strTableIncl(scope.symbols, s) +proc addUniqueSym*(scope: PScope, s: PSym): PSym = + result = strTableInclReportConflict(scope.symbols, s) proc openScope*(c: PContext): PScope {.discardable.} = result = PScope(parent: c.currentScope, @@ -177,24 +177,30 @@ proc ensureNoMissingOrUnusedSymbols(c: PContext; scope: PScope) = message(c.config, s.info, hintXDeclaredButNotUsed, getSymRepr(c.config, s)) s = nextIter(it, scope.symbols) -proc wrongRedefinition*(c: PContext; info: TLineInfo, s: string) = +proc wrongRedefinition*(c: PContext; info: TLineInfo, s: string; + conflictsWith: TLineInfo) = if c.config.cmd != cmdInteractive: - localError(c.config, info, "redefinition of '$1'" % s) + localError(c.config, info, + "redefinition of '$1'; previous declaration here: $2" % + [s, c.config $ conflictsWith]) proc addDecl*(c: PContext, sym: PSym, info: TLineInfo) = - if not c.currentScope.addUniqueSym(sym): - wrongRedefinition(c, info, sym.name.s) + let conflict = c.currentScope.addUniqueSym(sym) + if conflict != nil: + wrongRedefinition(c, info, sym.name.s, conflict.info) proc addDecl*(c: PContext, sym: PSym) = - if not c.currentScope.addUniqueSym(sym): - wrongRedefinition(c, sym.info, sym.name.s) + let conflict = c.currentScope.addUniqueSym(sym) + if conflict != nil: + wrongRedefinition(c, sym.info, sym.name.s, conflict.info) proc addPrelimDecl*(c: PContext, sym: PSym) = discard c.currentScope.addUniqueSym(sym) proc addDeclAt*(c: PContext; scope: PScope, sym: PSym) = - if not scope.addUniqueSym(sym): - wrongRedefinition(c, sym.info, sym.name.s) + let conflict = scope.addUniqueSym(sym) + if conflict != nil: + wrongRedefinition(c, sym.info, sym.name.s, conflict.info) proc addInterfaceDeclAux(c: PContext, sym: PSym) = if sfExported in sym.flags: @@ -212,7 +218,7 @@ proc addOverloadableSymAt*(c: PContext; scope: PScope, fn: PSym) = return let check = strTableGet(scope.symbols, fn.name) if check != nil and check.kind notin OverloadableSyms: - wrongRedefinition(c, fn.info, fn.name.s) + wrongRedefinition(c, fn.info, fn.name.s, check.info) else: scope.addSym(fn) |