diff options
author | Araq <rumpf_a@web.de> | 2015-01-31 16:23:38 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-01-31 16:23:38 +0100 |
commit | ab5b8f53914c92875d72b278f966092426d57323 (patch) | |
tree | 05fd12f5a52d068fa7a9037d89d7fb22cd7a33c6 | |
parent | 43e5e3ac22e359cf0c328e1c36627187c6c80efd (diff) | |
download | Nim-ab5b8f53914c92875d72b278f966092426d57323.tar.gz |
fixes #1988
-rw-r--r-- | compiler/sigmatch.nim | 12 | ||||
-rw-r--r-- | tests/typerel/tsymchoice_for_expr.nim | 15 |
2 files changed, 22 insertions, 5 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 549f1f9ad..2e37f3bf1 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1300,7 +1300,6 @@ proc paramTypesMatch*(m: var TCandidate, f, a: PType, # incorrect to simply use the first fitting match. However, to implement # this correctly is inefficient. We have to copy `m` here to be able to # roll back the side effects of the unification algorithm. - let c = m.c var x, y, z: TCandidate initCandidate(c, x, m.callee) @@ -1329,12 +1328,15 @@ proc paramTypesMatch*(m: var TCandidate, f, a: PType, y = z # z is as good as x if x.state == csEmpty: result = nil - elif (y.state == csMatch) and (cmpCandidates(x, y) == 0): + elif y.state == csMatch and cmpCandidates(x, y) == 0: if x.state != csMatch: internalError(arg.info, "x.state is not csMatch") - # ambiguous: more than one symbol fits - result = nil - else: + # ambiguous: more than one symbol fits! + # See tsymchoice_for_expr as an example. 'f.kind == tyExpr' should match + # anyway: + if f.kind == tyExpr: result = arg + else: result = nil + else: # only one valid interpretation found: markUsed(arg.info, arg.sons[best].sym) styleCheckUse(arg.info, arg.sons[best].sym) diff --git a/tests/typerel/tsymchoice_for_expr.nim b/tests/typerel/tsymchoice_for_expr.nim new file mode 100644 index 000000000..4c1f52bef --- /dev/null +++ b/tests/typerel/tsymchoice_for_expr.nim @@ -0,0 +1,15 @@ +# bug #1988 + +template t(e: expr) = discard + +proc positive(x: int): int = +x +proc negative(x: int): int = -x +proc negative(x: float): float = -x + +proc p1 = t(negative) +proc p2[X] = t(positive) +proc p3[X] = t(negative) + +p1() # This compiles. +p2[int]() # This compiles. +p3[int]() # This raises an error. |