compiler: better error messages (#5613)

This commit is contained in:
Andreas Rumpf
2017-03-26 20:24:06 +02:00
committed by GitHub
parent 481d8ba24a
commit d02486aa48
8 changed files with 37 additions and 29 deletions

View File

@@ -355,7 +355,7 @@ proc semOpAux(c: PContext, n: PNode) =
var a = n.sons[i]
if a.kind == nkExprEqExpr and sonsLen(a) == 2:
var info = a.sons[0].info
a.sons[0] = newIdentNode(considerQuotedIdent(a.sons[0]), info)
a.sons[0] = newIdentNode(considerQuotedIdent(a.sons[0], a), info)
a.sons[1] = semExprWithType(c, a.sons[1], flags)
a.typ = a.sons[1].typ
else:
@@ -1076,7 +1076,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
n.sons[0] = semExprWithType(c, n.sons[0], flags+{efDetermineType})
#restoreOldStyleType(n.sons[0])
var i = considerQuotedIdent(n.sons[1])
var i = considerQuotedIdent(n.sons[1], n)
var ty = n.sons[0].typ
var f: PSym = nil
result = nil
@@ -1160,7 +1160,7 @@ proc dotTransformation(c: PContext, n: PNode): PNode =
addSon(result, n.sons[1])
addSon(result, copyTree(n[0]))
else:
var i = considerQuotedIdent(n.sons[1])
var i = considerQuotedIdent(n.sons[1], n)
result = newNodeI(nkDotCall, n.info)
result.flags.incl nfDotField
addSon(result, newIdentNode(i, n[1].info))
@@ -1280,7 +1280,7 @@ proc semArrayAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
c.p.bracketExpr = oldBracketExpr
proc propertyWriteAccess(c: PContext, n, nOrig, a: PNode): PNode =
var id = considerQuotedIdent(a[1])
var id = considerQuotedIdent(a[1], a)
var setterId = newIdentNode(getIdent(id.s & '='), n.info)
# a[0] is already checked for semantics, that does ``builtinFieldAccess``
# this is ugly. XXX Semantic checking should use the ``nfSem`` flag for
@@ -1529,7 +1529,7 @@ proc lookUpForDefined(c: PContext, n: PNode, onlyCurrentScope: bool): PSym =
checkSonsLen(n, 2)
var m = lookUpForDefined(c, n.sons[0], onlyCurrentScope)
if m != nil and m.kind == skModule:
let ident = considerQuotedIdent(n[1])
let ident = considerQuotedIdent(n[1], n)
if m == c.module:
result = strTableGet(c.topLevelScope.symbols, ident)
else:
@@ -1548,7 +1548,7 @@ proc semDefined(c: PContext, n: PNode, onlyCurrentScope: bool): PNode =
checkSonsLen(n, 2)
# we replace this node by a 'true' or 'false' node:
result = newIntNode(nkIntLit, 0)
if not onlyCurrentScope and considerQuotedIdent(n[0]).s == "defined":
if not onlyCurrentScope and considerQuotedIdent(n[0], n).s == "defined":
if n.sons[1].kind != nkIdent:
localError(n.info, "obsolete usage of 'defined', use 'declared' instead")
elif condsyms.isDefined(n.sons[1].ident):
@@ -2097,7 +2097,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
if it.kind != nkExprColonExpr:
localError(n.info, errNamedExprExpected)
break
let id = considerQuotedIdent(it.sons[0])
let id = considerQuotedIdent(it.sons[0], it)
if containsOrIncl(ids, id.id):
localError(it.info, errFieldInitTwice, id.s)