Skip to content

Commit 97a6f42

Browse files
authored
fix generic converter subtype match regression (#25015)
fixes #25014 `implicitConv` tries to instantiate the supertype to convert to, previously the bindings of `m` was shared with the bindings of the converter but now an isolated match `convMatch` holds the bindings, so `convMatch` is now used in the call to `implicitConv` instead of `m` so that its bindings are used when instantiating the supertype.
1 parent 334848f commit 97a6f42

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

compiler/sigmatch.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,8 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType,
23282328
# it is correct
23292329
var param: PNode = nil
23302330
if srca == isSubtype:
2331-
param = implicitConv(nkHiddenSubConv, src, copyTree(arg), m, c)
2331+
# convMatch used here to use its bindings to instantiate subtype:
2332+
param = implicitConv(nkHiddenSubConv, src, copyTree(arg), convMatch, c)
23322333
elif src.kind in {tyVar}:
23332334
# Analyse the converter return type.
23342335
param = newNodeIT(nkHiddenAddr, arg.info, s.typ.firstParamType)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# issue #25014
2+
3+
type
4+
FooBase[T] {.inheritable.} = object
5+
val: T
6+
FooChild[T] = object of FooBase[T]
7+
8+
converter toValue*[T](r: FooBase[T]): T = r.val
9+
10+
proc foo(a: int) = discard
11+
var f: FooChild[int]
12+
foo(f)
13+
proc fooGeneric[T](a: T) = discard
14+
fooGeneric(f)

0 commit comments

Comments
 (0)