some steps to improve the type mismatches with the new
generic instantiation logic
This commit is contained in:
parent
8b933e470e
commit
3e79e9f981
3 changed files with 27 additions and 10 deletions
|
|
@ -828,7 +828,10 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
|
||||||
matches(c, n, copyTree(n), m)
|
matches(c, n, copyTree(n), m)
|
||||||
|
|
||||||
if m.state != csMatch:
|
if m.state != csMatch:
|
||||||
LocalError(n.info, errWrongNumberOfArguments)
|
var err = "cannot instantiate " & typeToString(s.typ) & "\n" &
|
||||||
|
"got: (" & describeArgs(c, n) & ")\n" &
|
||||||
|
"but expected: (" & describeArgs(c, s.typ.n, 0) & ")"
|
||||||
|
LocalError(n.info, errGenerated, err)
|
||||||
return newOrPrevType(tyError, prev, c)
|
return newOrPrevType(tyError, prev, c)
|
||||||
|
|
||||||
var isConcrete = true
|
var isConcrete = true
|
||||||
|
|
|
||||||
|
|
@ -180,15 +180,9 @@ proc argTypeToString(arg: PNode): string =
|
||||||
else:
|
else:
|
||||||
result = arg.typ.typeToString
|
result = arg.typ.typeToString
|
||||||
|
|
||||||
proc NotFoundError*(c: PContext, n: PNode) =
|
proc describeArgs*(c: PContext, n: PNode, startIdx = 1): string =
|
||||||
# Gives a detailed error message; this is separated from semOverloadedCall,
|
result = ""
|
||||||
# as semOverlodedCall is already pretty slow (and we need this information
|
for i in countup(startIdx, n.len - 1):
|
||||||
# only in case of an error).
|
|
||||||
if c.InCompilesContext > 0:
|
|
||||||
# fail fast:
|
|
||||||
GlobalError(n.info, errTypeMismatch, "")
|
|
||||||
var result = msgKindToString(errTypeMismatch)
|
|
||||||
for i in countup(1, sonsLen(n) - 1):
|
|
||||||
var arg = n.sons[i]
|
var arg = n.sons[i]
|
||||||
if n.sons[i].kind == nkExprEqExpr:
|
if n.sons[i].kind == nkExprEqExpr:
|
||||||
add(result, renderTree(n.sons[i].sons[0]))
|
add(result, renderTree(n.sons[i].sons[0]))
|
||||||
|
|
@ -204,6 +198,16 @@ proc NotFoundError*(c: PContext, n: PNode) =
|
||||||
if arg.typ.kind == tyError: return
|
if arg.typ.kind == tyError: return
|
||||||
add(result, argTypeToString(arg))
|
add(result, argTypeToString(arg))
|
||||||
if i != sonsLen(n) - 1: add(result, ", ")
|
if i != sonsLen(n) - 1: add(result, ", ")
|
||||||
|
|
||||||
|
proc NotFoundError*(c: PContext, n: PNode) =
|
||||||
|
# Gives a detailed error message; this is separated from semOverloadedCall,
|
||||||
|
# as semOverlodedCall is already pretty slow (and we need this information
|
||||||
|
# only in case of an error).
|
||||||
|
if c.InCompilesContext > 0:
|
||||||
|
# fail fast:
|
||||||
|
GlobalError(n.info, errTypeMismatch, "")
|
||||||
|
var result = msgKindToString(errTypeMismatch)
|
||||||
|
add(result, describeArgs(c, n))
|
||||||
add(result, ')')
|
add(result, ')')
|
||||||
var candidates = ""
|
var candidates = ""
|
||||||
var o: TOverloadIter
|
var o: TOverloadIter
|
||||||
|
|
|
||||||
10
tests/compile/tgeneric4.nim
Normal file
10
tests/compile/tgeneric4.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
type
|
||||||
|
TIDGen*[A: Ordinal] = object
|
||||||
|
next: A
|
||||||
|
free: seq[A]
|
||||||
|
|
||||||
|
proc newIDGen*[A]: TIDGen[A] =
|
||||||
|
newSeq result.free, 0
|
||||||
|
|
||||||
|
var x = newIDGen[int]()
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue