diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 6324b157b1..5094e61aed 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -2328,7 +2328,8 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType, # it is correct var param: PNode = nil if srca == isSubtype: - param = implicitConv(nkHiddenSubConv, src, copyTree(arg), m, c) + # convMatch used here to use its bindings to instantiate subtype: + param = implicitConv(nkHiddenSubConv, src, copyTree(arg), convMatch, c) elif src.kind in {tyVar}: # Analyse the converter return type. param = newNodeIT(nkHiddenAddr, arg.info, s.typ.firstParamType) diff --git a/tests/converter/tgenericsubtypeconverter.nim b/tests/converter/tgenericsubtypeconverter.nim new file mode 100644 index 0000000000..c364c5e127 --- /dev/null +++ b/tests/converter/tgenericsubtypeconverter.nim @@ -0,0 +1,14 @@ +# issue #25014 + +type + FooBase[T] {.inheritable.} = object + val: T + FooChild[T] = object of FooBase[T] + +converter toValue*[T](r: FooBase[T]): T = r.val + +proc foo(a: int) = discard +var f: FooChild[int] +foo(f) +proc fooGeneric[T](a: T) = discard +fooGeneric(f)