improve the error message for #4659; closes #4659

This commit is contained in:
Andreas Rumpf
2018-02-25 17:43:28 +01:00
parent b35ee82c48
commit 27e32e0a7d

View File

@@ -169,21 +169,24 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
else:
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 &
"\n required type: ")
if err.firstMismatch != 0 and n.len > 1:
let cond = n.len > 2
if cond:
candidates.add(" first type mismatch at position: " & $err.firstMismatch &
"\n required type: ")
var wanted, got: PType = nil
if err.firstMismatch < err.sym.typ.len:
wanted = err.sym.typ.sons[err.firstMismatch]
candidates.add typeToString(wanted)
if cond: candidates.add typeToString(wanted)
else:
candidates.add "none"
if cond: candidates.add "none"
if err.firstMismatch < n.len:
candidates.add "\n but expression '"
candidates.add renderTree(n[err.firstMismatch])
candidates.add "' is of type: "
if cond:
candidates.add "\n but expression '"
candidates.add renderTree(n[err.firstMismatch])
candidates.add "' is of type: "
got = n[err.firstMismatch].typ
candidates.add typeToString(got)
if cond: candidates.add typeToString(got)
if wanted != nil and got != nil:
effectProblem(wanted, got, candidates)
candidates.add "\n"