nicer error messages (untested)
This commit is contained in:
parent
fdf996925b
commit
7a48942719
9 changed files with 82 additions and 50 deletions
|
|
@ -22,6 +22,7 @@ type
|
|||
TCandidateState* = enum
|
||||
csEmpty, csMatch, csNoMatch
|
||||
|
||||
CandidateErrors* = seq[PSym]
|
||||
TCandidate* {.final.} = object
|
||||
c*: PContext
|
||||
exactMatches*: int # also misused to prefer iters over procs
|
||||
|
|
@ -45,7 +46,7 @@ type
|
|||
# a distrinct type
|
||||
typedescMatched: bool
|
||||
inheritancePenalty: int # to prefer closest father object type
|
||||
errors*: seq[string] # additional clarifications to be displayed to the
|
||||
errors*: CandidateErrors # additional clarifications to be displayed to the
|
||||
# user if overload resolution fails
|
||||
|
||||
TTypeRelation* = enum # order is important!
|
||||
|
|
@ -202,16 +203,17 @@ proc writeMatches*(c: TCandidate) =
|
|||
writeln(stdout, "intconv matches: " & $c.intConvMatches)
|
||||
writeln(stdout, "generic matches: " & $c.genericMatches)
|
||||
|
||||
proc argTypeToString(arg: PNode): string =
|
||||
proc argTypeToString(arg: PNode; prefer: TPreferedDesc): string =
|
||||
if arg.kind in nkSymChoices:
|
||||
result = typeToString(arg[0].typ)
|
||||
result = typeToString(arg[0].typ, prefer)
|
||||
for i in 1 .. <arg.len:
|
||||
result.add(" | ")
|
||||
result.add typeToString(arg[i].typ)
|
||||
result.add typeToString(arg[i].typ, prefer)
|
||||
else:
|
||||
result = arg.typ.typeToString
|
||||
result = arg.typ.typeToString(prefer)
|
||||
|
||||
proc describeArgs*(c: PContext, n: PNode, startIdx = 1): string =
|
||||
proc describeArgs*(c: PContext, n: PNode, startIdx = 1;
|
||||
prefer: TPreferedDesc = preferName): string =
|
||||
result = ""
|
||||
for i in countup(startIdx, n.len - 1):
|
||||
var arg = n.sons[i]
|
||||
|
|
@ -227,7 +229,7 @@ proc describeArgs*(c: PContext, n: PNode, startIdx = 1): string =
|
|||
arg = c.semOperand(c, n.sons[i])
|
||||
n.sons[i] = arg
|
||||
if arg.typ.kind == tyError: return
|
||||
add(result, argTypeToString(arg))
|
||||
add(result, argTypeToString(arg, prefer))
|
||||
if i != sonsLen(n) - 1: add(result, ", ")
|
||||
|
||||
proc typeRel*(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation
|
||||
|
|
@ -480,8 +482,8 @@ proc matchUserTypeClass*(c: PContext, m: var TCandidate,
|
|||
dummyParam.typ = dummyType
|
||||
addDecl(c, dummyParam)
|
||||
|
||||
var checkedBody = c.semTryExpr(c, body.n[3].copyTree, bufferErrors = false)
|
||||
m.errors = bufferedMsgs
|
||||
var checkedBody = c.semTryExpr(c, body.n[3].copyTree)
|
||||
#m.errors = bufferedMsgs
|
||||
clearBufferedMsgs()
|
||||
if checkedBody == nil: return isNone
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue