Skip to content

Commit f7c94b7

Browse files
committed
switched chosen overload
1 parent d5e5170 commit f7c94b7

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ trait Applications extends Compatibility {
15031503

15041504
private def onMethod(tp: Type, followApply: Boolean)(p: TermRef => Boolean)(using Context): Boolean = tp match {
15051505
case methRef: TermRef if methRef.widenSingleton.isInstanceOf[MethodicType] =>
1506-
p(methRef)
1506+
p(methRef) || tp.member(nme.apply).hasAltWith(d => p(TermRef(tp, nme.apply, d)))
15071507
case mt: MethodicType =>
15081508
p(mt.narrow)
15091509
case _ =>
@@ -1644,7 +1644,7 @@ trait Applications extends Compatibility {
16441644
tp2.isVarArgsMethod
16451645
&& isApplicableMethodRef(alt2, tp1.paramInfos.map(_.repeatedToSingle), WildcardType, ArgMatch.Compatible)
16461646
else
1647-
isApplicableMethodRef(alt2, tp1.paramInfos, WildcardType, ArgMatch.Compatible)
1647+
isApplicableMethodRef(alt2, tp1.paramInfos, WildcardType, ArgMatch.Compatible)// || isApplicableType(alt2, tp1.paramInfos, WildcardType)
16481648
}
16491649
case tp1: PolyType => // (2)
16501650
inContext(ctx.fresh.setExploreTyperState()) {
@@ -1787,8 +1787,7 @@ trait Applications extends Compatibility {
17871787
def narrowMostSpecific(alts: List[TermRef])(using Context): List[TermRef] = {
17881788
record("narrowMostSpecific")
17891789
alts match {
1790-
case Nil => alts
1791-
case _ :: Nil => alts
1790+
case Nil | _ :: Nil => alts
17921791
case alt1 :: alt2 :: Nil =>
17931792
compare(alt1, alt2) match {
17941793
case 1 => alt1 :: Nil
@@ -1955,7 +1954,10 @@ trait Applications extends Compatibility {
19551954
}
19561955

19571956
def narrowByTypes(alts: List[TermRef], argTypes: List[Type], resultType: Type): List[TermRef] =
1958-
alts.filterConserve(isApplicableMethodRef(_, argTypes, resultType, ArgMatch.CompatibleCAP))
1957+
alts.filterConserve { alt =>
1958+
isApplicableMethodRef(alt, argTypes, resultType, ArgMatch.CompatibleCAP)
1959+
|| isApplicableType(alt, argTypes, resultType)
1960+
}
19591961

19601962
/** Normalization steps before checking arguments:
19611963
*

tests/run/i18294.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def f(s: Int): String = "a"
2+
def f: Int => String = _ => "b"
3+
4+
@main def Test =
5+
val test: Int => String = f
6+
assert(test(0) == "b")

0 commit comments

Comments
 (0)