fixes #8043
This commit is contained in:
parent
e63c66b810
commit
0694c9080f
3 changed files with 34 additions and 4 deletions
|
|
@ -189,15 +189,18 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
|
||||||
if err.firstMismatch != 0 and n.len > 1:
|
if err.firstMismatch != 0 and n.len > 1:
|
||||||
let cond = n.len > 2
|
let cond = n.len > 2
|
||||||
if cond:
|
if cond:
|
||||||
candidates.add(" first type mismatch at position: " & $err.firstMismatch &
|
candidates.add(" first type mismatch at position: " & $abs(err.firstMismatch))
|
||||||
"\n required type: ")
|
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
|
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]
|
wanted = err.sym.typ.sons[err.firstMismatch]
|
||||||
if cond: candidates.add typeToString(wanted)
|
if cond: candidates.add typeToString(wanted)
|
||||||
else:
|
else:
|
||||||
if cond: candidates.add "none"
|
if cond: candidates.add "none"
|
||||||
if err.firstMismatch < n.len:
|
if err.firstMismatch > 0 and err.firstMismatch < n.len:
|
||||||
if cond:
|
if cond:
|
||||||
candidates.add "\n but expression '"
|
candidates.add "\n but expression '"
|
||||||
candidates.add renderTree(n[err.firstMismatch])
|
candidates.add renderTree(n[err.firstMismatch])
|
||||||
|
|
|
||||||
|
|
@ -2252,11 +2252,13 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
if n.sons[a].sons[0].kind != nkIdent:
|
if n.sons[a].sons[0].kind != nkIdent:
|
||||||
localError(c.config, n.sons[a].info, "named parameter has to be an identifier")
|
localError(c.config, n.sons[a].info, "named parameter has to be an identifier")
|
||||||
m.state = csNoMatch
|
m.state = csNoMatch
|
||||||
|
m.firstMismatch = -a
|
||||||
return
|
return
|
||||||
formal = getSymFromList(m.callee.n, n.sons[a].sons[0].ident, 1)
|
formal = getSymFromList(m.callee.n, n.sons[a].sons[0].ident, 1)
|
||||||
if formal == nil:
|
if formal == nil:
|
||||||
# no error message!
|
# no error message!
|
||||||
m.state = csNoMatch
|
m.state = csNoMatch
|
||||||
|
m.firstMismatch = -a
|
||||||
return
|
return
|
||||||
if containsOrIncl(marker, formal.position):
|
if containsOrIncl(marker, formal.position):
|
||||||
# already in namedParams, so no match
|
# 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])
|
n.sons[a].sons[1], n.sons[a].sons[1])
|
||||||
if arg == nil:
|
if arg == nil:
|
||||||
m.state = csNoMatch
|
m.state = csNoMatch
|
||||||
|
m.firstMismatch = a
|
||||||
return
|
return
|
||||||
checkConstraint(n.sons[a].sons[1])
|
checkConstraint(n.sons[a].sons[1])
|
||||||
if m.baseTypeMatch:
|
if m.baseTypeMatch:
|
||||||
|
|
|
||||||
24
tests/errmsgs/tunknown_named_parameter.nim
Normal file
24
tests/errmsgs/tunknown_named_parameter.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
discard """
|
||||||
|
cmd: "nim check $file"
|
||||||
|
errormsg: "type mismatch: got <string, set[char], maxsplits: int literal(1)>"
|
||||||
|
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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue