fixes #1988
This commit is contained in:
parent
43e5e3ac22
commit
ab5b8f5391
2 changed files with 22 additions and 5 deletions
|
|
@ -1300,7 +1300,6 @@ proc paramTypesMatch*(m: var TCandidate, f, a: PType,
|
||||||
# incorrect to simply use the first fitting match. However, to implement
|
# 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
|
# this correctly is inefficient. We have to copy `m` here to be able to
|
||||||
# roll back the side effects of the unification algorithm.
|
# roll back the side effects of the unification algorithm.
|
||||||
|
|
||||||
let c = m.c
|
let c = m.c
|
||||||
var x, y, z: TCandidate
|
var x, y, z: TCandidate
|
||||||
initCandidate(c, x, m.callee)
|
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
|
y = z # z is as good as x
|
||||||
if x.state == csEmpty:
|
if x.state == csEmpty:
|
||||||
result = nil
|
result = nil
|
||||||
elif (y.state == csMatch) and (cmpCandidates(x, y) == 0):
|
elif y.state == csMatch and cmpCandidates(x, y) == 0:
|
||||||
if x.state != csMatch:
|
if x.state != csMatch:
|
||||||
internalError(arg.info, "x.state is not csMatch")
|
internalError(arg.info, "x.state is not csMatch")
|
||||||
# ambiguous: more than one symbol fits
|
# ambiguous: more than one symbol fits!
|
||||||
result = nil
|
# See tsymchoice_for_expr as an example. 'f.kind == tyExpr' should match
|
||||||
else:
|
# anyway:
|
||||||
|
if f.kind == tyExpr: result = arg
|
||||||
|
else: result = nil
|
||||||
|
else:
|
||||||
# only one valid interpretation found:
|
# only one valid interpretation found:
|
||||||
markUsed(arg.info, arg.sons[best].sym)
|
markUsed(arg.info, arg.sons[best].sym)
|
||||||
styleCheckUse(arg.info, arg.sons[best].sym)
|
styleCheckUse(arg.info, arg.sons[best].sym)
|
||||||
|
|
|
||||||
15
tests/typerel/tsymchoice_for_expr.nim
Normal file
15
tests/typerel/tsymchoice_for_expr.nim
Normal file
|
|
@ -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.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue