diff options
author | Zahary Karadjov <zahary@gmail.com> | 2013-05-28 19:52:29 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2013-08-19 01:45:16 +0300 |
commit | 3e79e9f98185148899313da0a7436f861029c10c (patch) | |
tree | 556a5b806b28478c40e67a5df853d8f18d03a990 | |
parent | 8b933e470e46c5f314d81529626c15dab4de228f (diff) | |
download | Nim-3e79e9f98185148899313da0a7436f861029c10c.tar.gz |
some steps to improve the type mismatches with the new
generic instantiation logic
-rw-r--r-- | compiler/semtypes.nim | 5 | ||||
-rw-r--r-- | compiler/sigmatch.nim | 22 | ||||
-rw-r--r-- | tests/compile/tgeneric4.nim | 10 |
3 files changed, 27 insertions, 10 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 703b55ace..8ae23f851 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -828,7 +828,10 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType = matches(c, n, copyTree(n), m) 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) var isConcrete = true diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 98fa1e1f9..41268d6d0 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -180,15 +180,9 @@ proc argTypeToString(arg: PNode): string = else: result = arg.typ.typeToString -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) - for i in countup(1, sonsLen(n) - 1): +proc describeArgs*(c: PContext, n: PNode, startIdx = 1): string = + result = "" + for i in countup(startIdx, n.len - 1): var arg = n.sons[i] if n.sons[i].kind == nkExprEqExpr: add(result, renderTree(n.sons[i].sons[0])) @@ -204,6 +198,16 @@ proc NotFoundError*(c: PContext, n: PNode) = if arg.typ.kind == tyError: return add(result, argTypeToString(arg)) 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, ')') var candidates = "" var o: TOverloadIter diff --git a/tests/compile/tgeneric4.nim b/tests/compile/tgeneric4.nim new file mode 100644 index 000000000..f79096636 --- /dev/null +++ b/tests/compile/tgeneric4.nim @@ -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]() + |