@@ -1501,13 +1501,20 @@ trait Applications extends Compatibility {
1501
1501
isApplicableMethodRef(_, args, resultType, ArgMatch .Compatible )
1502
1502
}
1503
1503
1504
- private def onMethod (tp : Type , followApply : Boolean )(p : TermRef => Boolean )(using Context ): Boolean = tp match {
1504
+
1505
+ private def onMethod (tp : Type , followApply : Boolean )(p : TermRef => Boolean )(using Context ): Boolean =
1506
+ def hasApply : Boolean =
1507
+ followApply && tp.member(nme.apply).hasAltWith(d => p(TermRef (tp, nme.apply, d)))
1508
+
1509
+ tp match {
1510
+ case expr : TermRef if expr.widenSingleton.isInstanceOf [ExprType ] =>
1511
+ hasApply
1505
1512
case methRef : TermRef if methRef.widenSingleton.isInstanceOf [MethodicType ] =>
1506
1513
p(methRef)
1507
1514
case mt : MethodicType =>
1508
1515
p(mt.narrow)
1509
1516
case _ =>
1510
- followApply && tp.member(nme.apply).hasAltWith(d => p( TermRef (tp, nme.apply, d)))
1517
+ hasApply
1511
1518
}
1512
1519
1513
1520
/** Does `tp` have an extension method named `xname` with this-argument `argType` and
@@ -1644,7 +1651,7 @@ trait Applications extends Compatibility {
1644
1651
tp2.isVarArgsMethod
1645
1652
&& isApplicableMethodRef(alt2, tp1.paramInfos.map(_.repeatedToSingle), WildcardType , ArgMatch .Compatible )
1646
1653
else
1647
- isApplicableMethodRef(alt2, tp1.paramInfos, WildcardType , ArgMatch .Compatible )
1654
+ isApplicableTerm( tp1.paramInfos, WildcardType , ArgMatch .Compatible )(alt2 )
1648
1655
}
1649
1656
case tp1 : PolyType => // (2)
1650
1657
inContext(ctx.fresh.setExploreTyperState()) {
@@ -1787,8 +1794,7 @@ trait Applications extends Compatibility {
1787
1794
def narrowMostSpecific (alts : List [TermRef ])(using Context ): List [TermRef ] = {
1788
1795
record(" narrowMostSpecific" )
1789
1796
alts match {
1790
- case Nil => alts
1791
- case _ :: Nil => alts
1797
+ case Nil | _ :: Nil => alts
1792
1798
case alt1 :: alt2 :: Nil =>
1793
1799
compare(alt1, alt2) match {
1794
1800
case 1 => alt1 :: Nil
@@ -1920,6 +1926,15 @@ trait Applications extends Compatibility {
1920
1926
else resolve(alts)
1921
1927
end resolveOverloaded
1922
1928
1929
+ def isApplicableTerm (argTypes : List [Type ], resultType : Type , argMatch : ArgMatch )(using Context ): TermRef => Boolean =
1930
+ onMethod(_, argTypes.nonEmpty):
1931
+ isApplicableMethodRef(_, argTypes, resultType, argMatch)
1932
+
1933
+ def isApplicableTerm (argTypes : List [Tree ], resultType : Type , keepConstraint : Boolean , argMatch : ArgMatch )(using Context ): TermRef => Boolean =
1934
+ onMethod(_, argTypes.nonEmpty):
1935
+ isApplicableMethodRef(_, argTypes, resultType, keepConstraint, argMatch)
1936
+
1937
+
1923
1938
/** This private version of `resolveOverloaded` does the bulk of the work of
1924
1939
* overloading resolution, but does neither result adaptation nor apply insertion.
1925
1940
* It might be called twice from the public `resolveOverloaded` method, once with
@@ -1955,7 +1970,8 @@ trait Applications extends Compatibility {
1955
1970
}
1956
1971
1957
1972
def narrowByTypes (alts : List [TermRef ], argTypes : List [Type ], resultType : Type ): List [TermRef ] =
1958
- alts.filterConserve(isApplicableMethodRef(_, argTypes, resultType, ArgMatch .CompatibleCAP ))
1973
+ alts.filterConserve:
1974
+ isApplicableTerm(argTypes, resultType, ArgMatch .CompatibleCAP )
1959
1975
1960
1976
/** Normalization steps before checking arguments:
1961
1977
*
@@ -2030,9 +2046,8 @@ trait Applications extends Compatibility {
2030
2046
alts
2031
2047
2032
2048
def narrowByTrees (alts : List [TermRef ], args : List [Tree ], resultType : Type ): List [TermRef ] =
2033
- alts.filterConserve(alt =>
2034
- isApplicableMethodRef(alt, args, resultType, keepConstraint = false , ArgMatch .CompatibleCAP )
2035
- )
2049
+ alts.filterConserve:
2050
+ isApplicableTerm(args, resultType, keepConstraint = false , ArgMatch .CompatibleCAP )
2036
2051
2037
2052
record(" resolveOverloaded.FunProto" , alts.length)
2038
2053
val alts1 = narrowBySize(alts)
0 commit comments