better error messages: use <T1, T2> instead of (T1, T2) in order to prevent confusions with tuple types

This commit is contained in:
Araq 2018-02-10 20:39:05 +01:00
commit ef6eda4cb4
25 changed files with 62 additions and 62 deletions

View file

@ -272,7 +272,7 @@ const
errXStackEscape: "address of '$1' may not escape its stack frame",
errVarForOutParamNeededX: "for a \'var\' type a variable needs to be passed; but '$1' is immutable",
errPureTypeMismatch: "type mismatch",
errTypeMismatch: "type mismatch: got (",
errTypeMismatch: "type mismatch: got <",
errButExpected: "but expected one of: ",
errButExpectedX: "but expected \'$1\'",
errAmbiguousCallXYZ: "ambiguous call; both $1 and $2 match for: $3",

View file

@ -156,14 +156,14 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
add(candidates, err.sym.getProcHeader(prefer))
add(candidates, "\n")
if err.firstMismatch != 0 and n.len > 2:
add(candidates, "first type mismatch at position: " & $err.firstMismatch &
"\nrequired type: ")
add(candidates, " first type mismatch at position: " & $err.firstMismatch &
"\n required type: ")
if err.firstMismatch < err.sym.typ.len:
candidates.add typeToString(err.sym.typ.sons[err.firstMismatch])
else:
candidates.add "none"
if err.firstMismatch < n.len:
candidates.add "\nbut expression '"
candidates.add "\n but expression '"
candidates.add renderTree(n[err.firstMismatch])
candidates.add "' is of type: "
candidates.add typeToString(n[err.firstMismatch].typ)
@ -190,7 +190,7 @@ proc notFoundError*(c: PContext, n: PNode, errors: CandidateErrors) =
let (prefer, candidates) = presentFailedCandidates(c, n, errors)
var result = msgKindToString(errTypeMismatch)
add(result, describeArgs(c, n, 1, prefer))
add(result, ')')
add(result, '>')
if candidates != "":
add(result, "\n" & msgKindToString(errButExpected) & "\n" & candidates)
localError(n.info, errGenerated, result & "\nexpression: " & $n)

View file

@ -735,7 +735,7 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
hasErrorType = true
break
if not hasErrorType:
add(msg, ")\n" & msgKindToString(errButExpected) & "\n" &
add(msg, ">\n" & msgKindToString(errButExpected) & "\n" &
typeToString(n.sons[0].typ))
localError(n.info, errGenerated, msg)
return errorNode(c, n)

View file

@ -1149,8 +1149,8 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
if m.state != csMatch:
let err = "cannot instantiate " & typeToString(t) & "\n" &
"got: (" & describeArgs(c, n) & ")\n" &
"but expected: (" & describeArgs(c, t.n, 0) & ")"
"got: <" & describeArgs(c, n) & ">\n" &
"but expected: <" & describeArgs(c, t.n, 0) & ">"
localError(n.info, errGenerated, err)
return newOrPrevType(tyError, prev, c)

View file

@ -1620,7 +1620,7 @@ proc typeMismatch*(info: TLineInfo, formal, actual: PType) =
let desc = typeToString(formal, preferDesc)
let x = if named == desc: named else: named & " = " & desc
var msg = msgKindToString(errTypeMismatch) &
typeToString(actual) & ") " &
typeToString(actual) & "> " &
msgKindToString(errButExpectedX) % [x]
if formal.kind == tyProc and actual.kind == tyProc: