diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 9e75f8cd4..53f7045dd 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -189,15 +189,18 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors): 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: ") + candidates.add(" first type mismatch at position: " & $abs(err.firstMismatch)) + if err.firstMismatch >= 0: candidates.add("\n required type: ") + else: candidates.add("\n unknown named parameter: " & $n[-err.firstMismatch][0]) var wanted, got: PType = nil - if err.firstMismatch < err.sym.typ.len: + if err.firstMismatch < 0: + discard + elif err.firstMismatch < err.sym.typ.len: wanted = err.sym.typ.sons[err.firstMismatch] if cond: candidates.add typeToString(wanted) else: if cond: candidates.add "none" - if err.firstMismatch < n.len: + if err.firstMismatch > 0 and err.firstMismatch < n.len: if cond: candidates.add "\n but expression '" candidates.add renderTree(n[err.firstMismatch]) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index e59496cca..407e34619 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -2252,11 +2252,13 @@ proc matchesAux(c: PContext, n, nOrig: PNode, if n.sons[a].sons[0].kind != nkIdent: localError(c.config, n.sons[a].info, "named parameter has to be an identifier") m.state = csNoMatch + m.firstMismatch = -a return formal = getSymFromList(m.callee.n, n.sons[a].sons[0].ident, 1) if formal == nil: # no error message! m.state = csNoMatch + m.firstMismatch = -a return if containsOrIncl(marker, formal.position): # already in namedParams, so no match @@ -2274,6 +2276,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode, n.sons[a].sons[1], n.sons[a].sons[1]) if arg == nil: m.state = csNoMatch + m.firstMismatch = a return checkConstraint(n.sons[a].sons[1]) if m.baseTypeMatch: diff --git a/tests/errmsgs/tunknown_named_parameter.nim b/tests/errmsgs/tunknown_named_parameter.nim new file mode 100644 index 000000000..b6b855136 --- /dev/null +++ b/tests/errmsgs/tunknown_named_parameter.nim @@ -0,0 +1,24 @@ +discard """ +cmd: "nim check $file" +errormsg: "type mismatch: got " +nimout: ''' +proc rsplit(s: string; sep: string; maxsplit: int = -1): seq[string] + first type mismatch at position: 2 + required type: string + but expression '{':'}' is of type: set[char] +proc rsplit(s: string; sep: char; maxsplit: int = -1): seq[string] + first type mismatch at position: 2 + required type: char + but expression '{':'}' is of type: set[char] +proc rsplit(s: string; seps: set[char] = Whitespace; maxsplit: int = -1): seq[string] + first type mismatch at position: 3 + unknown named parameter: maxsplits + +expression: rsplit("abc:def", {':'}, maxsplits = 1) +''' +""" + +# bug #8043 + +import strutils +"abc:def".rsplit({':'}, maxsplits = 1)