better error messages

This commit is contained in:
Araq
2018-03-18 12:04:22 +01:00
parent 4301744e49
commit b0994c7f92
3 changed files with 17 additions and 3 deletions

View File

@@ -820,7 +820,6 @@ proc parseIfExpr(p: var TParser, kind: TNodeKind): PNode =
if realInd(p):
p.currInd = p.tok.indent
wasIndented = true
echo result.info, " yes ", p.currInd
addSon(branch, parseExpr(p))
result.add branch
while sameInd(p) or not wasIndented:
@@ -964,6 +963,8 @@ proc parseTuple(p: var TParser, indentAllowed = false): PNode =
parMessage(p, errIdentifierExpected, p.tok)
break
if not sameInd(p): break
elif p.tok.tokType == tkParLe:
parMessage(p, errGenerated, "the syntax for tuple types is 'tuple[...]', not 'tuple(...)'")
else:
result = newNodeP(nkTupleClassTy, p)
@@ -985,6 +986,9 @@ proc parseParamList(p: var TParser, retColon = true): PNode =
a = parseIdentColonEquals(p, {withBothOptional, withPragma})
of tkParRi:
break
of tkVar:
parMessage(p, errGenerated, "the syntax is 'parameter: var T', not 'var parameter: T'")
break
else:
parMessage(p, errTokenExpected, ")")
break
@@ -2132,7 +2136,12 @@ proc parseTopLevelStmt(p: var TParser): PNode =
if p.tok.indent != 0:
if p.firstTok and p.tok.indent < 0: discard
elif p.tok.tokType != tkSemiColon:
parMessage(p, errInvalidIndentation)
# special casing for better error messages:
if p.tok.tokType == tkOpr and p.tok.ident.s == "*":
parMessage(p, errGenerated,
"invalid indentation; an export marker '*' follows the declared identifier")
else:
parMessage(p, errInvalidIndentation)
p.firstTok = false
case p.tok.tokType
of tkSemiColon:

View File

@@ -192,6 +192,10 @@ proc semConv(c: PContext, n: PNode): PNode =
result.addSon copyTree(n.sons[0])
# special case to make MyObject(x = 3) produce a nicer error message:
if n[1].kind == nkExprEqExpr and
targetType.skipTypes(abstractPtrs).kind == tyObject:
localError(n.info, "object contruction uses ':', not '='")
var op = semExprWithType(c, n.sons[1])
if targetType.isMetaType:
let final = inferWithMetatype(c, targetType, op, true)

View File

@@ -720,7 +720,8 @@ proc semObjectNode(c: PContext, n: PNode, prev: PType): PType =
addInheritedFields(c, check, pos, concreteBase)
else:
if concreteBase.kind != tyError:
localError(n.sons[1].info, errInheritanceOnlyWithNonFinalObjects)
localError(n.sons[1].info, "inheritance only works with non-final objects; " &
"to enable inheritance write '" & typeToString(realBase) & " of RootObj'")
base = nil
realBase = nil
if n.kind != nkObjectTy: internalError(n.info, "semObjectNode")