From 27e32e0a7d0931503803b26c24783dfd4433b715 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sun, 25 Feb 2018 17:43:28 +0100 Subject: [PATCH] improve the error message for #4659; closes #4659 --- compiler/semcall.nim | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 5bdd817d5..6fef11c48 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -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"