This commit is contained in:
Andreas Rumpf 2016-05-11 17:39:37 +02:00
commit 95ffeb6079
2 changed files with 18 additions and 5 deletions

View file

@ -221,6 +221,19 @@ when defined(nimfix):
else: else:
template fixSpelling(n: PNode; ident: PIdent; op: expr) = discard template fixSpelling(n: PNode; ident: PIdent; op: expr) = discard
proc errorUseQualifier*(c: PContext; info: TLineInfo; s: PSym) =
var err = "Error: ambiguous identifier: '" & s.name.s & "'"
var ti: TIdentIter
var candidate = initIdentIter(ti, c.importTable.symbols, s.name)
var i = 0
while candidate != nil:
if i == 0: err.add " --use "
else: err.add " or "
err.add candidate.owner.name.s & "." & candidate.name.s
candidate = nextIdentIter(ti, c.importTable.symbols)
inc i
localError(info, errGenerated, err)
proc lookUp*(c: PContext, n: PNode): PSym = proc lookUp*(c: PContext, n: PNode): PSym =
# Looks up a symbol. Generates an error in case of nil. # Looks up a symbol. Generates an error in case of nil.
case n.kind case n.kind
@ -243,7 +256,7 @@ proc lookUp*(c: PContext, n: PNode): PSym =
internalError(n.info, "lookUp") internalError(n.info, "lookUp")
return return
if contains(c.ambiguousSymbols, result.id): if contains(c.ambiguousSymbols, result.id):
localError(n.info, errUseQualifier, result.name.s) errorUseQualifier(c, n.info, result)
if result.kind == skStub: loadStub(result) if result.kind == skStub: loadStub(result)
type type
@ -261,11 +274,11 @@ proc qualifiedLookUp*(c: PContext, n: PNode, flags = {checkUndeclared}): PSym =
result = errorSym(c, n) result = errorSym(c, n)
elif checkAmbiguity in flags and result != nil and elif checkAmbiguity in flags and result != nil and
contains(c.ambiguousSymbols, result.id): contains(c.ambiguousSymbols, result.id):
localError(n.info, errUseQualifier, ident.s) errorUseQualifier(c, n.info, result)
of nkSym: of nkSym:
result = n.sym result = n.sym
if checkAmbiguity in flags and contains(c.ambiguousSymbols, result.id): if checkAmbiguity in flags and contains(c.ambiguousSymbols, result.id):
localError(n.info, errUseQualifier, n.sym.name.s) errorUseQualifier(c, n.info, n.sym)
of nkDotExpr: of nkDotExpr:
result = nil result = nil
var m = qualifiedLookUp(c, n.sons[0], flags*{checkUndeclared}) var m = qualifiedLookUp(c, n.sons[0], flags*{checkUndeclared})

View file

@ -213,7 +213,7 @@ proc semConv(c: PContext, n: PNode): PNode =
styleCheckUse(n.info, it.sym) styleCheckUse(n.info, it.sym)
markIndirect(c, it.sym) markIndirect(c, it.sym)
return it return it
localError(n.info, errUseQualifier, op.sons[0].sym.name.s) errorUseQualifier(c, n.info, op.sons[0].sym)
proc semCast(c: PContext, n: PNode): PNode = proc semCast(c: PContext, n: PNode): PNode =
## Semantically analyze a casting ("cast[type](param)") ## Semantically analyze a casting ("cast[type](param)")
@ -2227,7 +2227,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
elif n.len == 1: elif n.len == 1:
result = semObjConstr(c, n, flags) result = semObjConstr(c, n, flags)
elif contains(c.ambiguousSymbols, s.id): elif contains(c.ambiguousSymbols, s.id):
localError(n.info, errUseQualifier, s.name.s) errorUseQualifier(c, n.info, s)
elif s.magic == mNone: result = semDirectOp(c, n, flags) elif s.magic == mNone: result = semDirectOp(c, n, flags)
else: result = semMagic(c, n, s, flags) else: result = semMagic(c, n, s, flags)
of skProc, skMethod, skConverter, skIterator: of skProc, skMethod, skConverter, skIterator: