Skip to content

Commit 8cdb51d

Browse files
committed
switched chosen overload
added some tests found pattern Update compiler/src/dotty/tools/dotc/typer/Applications.scala fix
1 parent c90ad6b commit 8cdb51d

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,8 @@ trait Applications extends Compatibility {
15021502
}
15031503

15041504
private def onMethod(tp: Type, followApply: Boolean)(p: TermRef => Boolean)(using Context): Boolean = tp match {
1505+
case expr: TermRef if expr.widenSingleton.isInstanceOf[ExprType] =>
1506+
tp.member(nme.apply).hasAltWith(d => p(TermRef(tp, nme.apply, d)))
15051507
case methRef: TermRef if methRef.widenSingleton.isInstanceOf[MethodicType] =>
15061508
p(methRef)
15071509
case mt: MethodicType =>
@@ -1787,8 +1789,7 @@ trait Applications extends Compatibility {
17871789
def narrowMostSpecific(alts: List[TermRef])(using Context): List[TermRef] = {
17881790
record("narrowMostSpecific")
17891791
alts match {
1790-
case Nil => alts
1791-
case _ :: Nil => alts
1792+
case Nil | _ :: Nil => alts
17921793
case alt1 :: alt2 :: Nil =>
17931794
compare(alt1, alt2) match {
17941795
case 1 => alt1 :: Nil
@@ -1955,7 +1956,7 @@ trait Applications extends Compatibility {
19551956
}
19561957

19571958
def narrowByTypes(alts: List[TermRef], argTypes: List[Type], resultType: Type): List[TermRef] =
1958-
alts.filterConserve(isApplicableMethodRef(_, argTypes, resultType, ArgMatch.CompatibleCAP))
1959+
alts.filterConserve { isApplicableType(_, argTypes, resultType) }
19591960

19601961
/** Normalization steps before checking arguments:
19611962
*

tests/run/i18294.scala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
def f1(s: Int): String = "a"
2+
def f1: Int => String = _ => "b"
3+
4+
def f2(s: Int): String = "a"
5+
val f2: Int => String = _ => "b"
6+
7+
def f3(s: Int): String = "a"
8+
def f3(): Int => String = _ => "b"
9+
10+
object DefDef:
11+
def f4(s: Int): String = "a"
12+
def f4: Int => String = _ => "b"
13+
object DefVal:
14+
def f5(s: Int): String = "a"
15+
val f5: Int => String = _ => "b"
16+
17+
@main def Test =
18+
val test01: Int => String = f1
19+
val test02: Int => String = f2
20+
val test03: Int => String = f3
21+
22+
val test1: Int => String = DefDef.f4
23+
def dtest1: Int => String = DefDef.f4
24+
25+
val test2: Int => String = DefVal.f5
26+
def dtest2: Int => String = DefVal.f5
27+
28+
assert(test03(0) == "a")
29+
30+
assert(test01(0) == "b")
31+
assert(test02(0) == "b")
32+
33+
assert(test1(0) == "b")
34+
assert(dtest1(0) == "b")
35+
36+
assert(test2(0) == "b")
37+
assert(dtest2(0) == "b")

0 commit comments

Comments
 (0)