diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index e11afe261458..78c2ea133ce1 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1473,7 +1473,17 @@ trait Applications extends Compatibility { } } - /** Drop any implicit parameter section */ + /** Drop any leading type or implicit parameter sections */ + def stripInferrable(tp: Type)(using Context): Type = tp match { + case mt: MethodType if mt.isImplicitMethod => + stripInferrable(resultTypeApprox(mt)) + case pt: PolyType => + stripInferrable(pt.resType) + case _ => + tp + } + + /** Drop any leading implicit parameter sections */ def stripImplicit(tp: Type)(using Context): Type = tp match { case mt: MethodType if mt.isImplicitMethod => stripImplicit(resultTypeApprox(mt)) @@ -2042,7 +2052,7 @@ trait Applications extends Compatibility { skip(alt.widen) def resultIsMethod(tp: Type): Boolean = tp.widen.stripPoly match - case tp: MethodType => stripImplicit(tp.resultType).isInstanceOf[MethodType] + case tp: MethodType => stripInferrable(tp.resultType).isInstanceOf[MethodType] case _ => false record("resolveOverloaded.narrowedApplicable", candidates.length) diff --git a/tests/pos/i14451.scala b/tests/pos/i14451.scala new file mode 100644 index 000000000000..24c3e3fbe25e --- /dev/null +++ b/tests/pos/i14451.scala @@ -0,0 +1,27 @@ + +class Foo + +extension (dfVal: Foo) + def f0(step: Int): Foo = ??? + def f0: Foo = ??? +val v0 = (new Foo).f0 + +extension (dfVal: Foo) + def f1[T](step: Int): Foo = ??? + def f1: Foo = ??? +val v1 = (new Foo).f1 + +extension (dfVal: Foo) + def f2[T](step: Int): Foo = ??? + def f2[T]: Foo = ??? +val v2 = (new Foo).f2 + +extension [A](dfVal: Foo) + def f3[T](step: Int): Foo = ??? + def f3: Foo = ??? +val v3 = (new Foo).f3 + +extension [A](dfVal: Foo) + def f4[T](step: Int): Foo = ??? + def f4[T]: Foo = ??? +val v4 = (new Foo).f4