@@ -1518,13 +1518,20 @@ trait Applications extends Compatibility {
1518
1518
isApplicableMethodRef(_, args, resultType, ArgMatch .Compatible )
1519
1519
}
1520
1520
1521
- private def onMethod (tp : Type , followApply : Boolean )(p : TermRef => Boolean )(using Context ): Boolean = tp match {
1521
+
1522
+ private def onMethod (tp : Type , followApply : Boolean )(p : TermRef => Boolean )(using Context ): Boolean =
1523
+ def hasApply : Boolean =
1524
+ followApply && tp.member(nme.apply).hasAltWith(d => p(TermRef (tp, nme.apply, d)))
1525
+
1526
+ tp match {
1527
+ case expr : TermRef if expr.widenSingleton.isInstanceOf [ExprType ] =>
1528
+ hasApply
1522
1529
case methRef : TermRef if methRef.widenSingleton.isInstanceOf [MethodicType ] =>
1523
1530
p(methRef)
1524
1531
case mt : MethodicType =>
1525
1532
p(mt.narrow)
1526
1533
case _ =>
1527
- followApply && tp.member(nme.apply).hasAltWith(d => p( TermRef (tp, nme.apply, d)))
1534
+ hasApply
1528
1535
}
1529
1536
1530
1537
/** Does `tp` have an extension method named `xname` with this-argument `argType` and
@@ -1661,7 +1668,7 @@ trait Applications extends Compatibility {
1661
1668
tp2.isVarArgsMethod
1662
1669
&& isApplicableMethodRef(alt2, tp1.paramInfos.map(_.repeatedToSingle), WildcardType , ArgMatch .Compatible )
1663
1670
else
1664
- isApplicableMethodRef(alt2, tp1.paramInfos, WildcardType , ArgMatch .Compatible )
1671
+ isApplicableTerm( tp1.paramInfos, WildcardType , ArgMatch .Compatible )(alt2 )
1665
1672
}
1666
1673
case tp1 : PolyType => // (2)
1667
1674
inContext(ctx.fresh.setExploreTyperState()) {
@@ -1804,8 +1811,7 @@ trait Applications extends Compatibility {
1804
1811
def narrowMostSpecific (alts : List [TermRef ])(using Context ): List [TermRef ] = {
1805
1812
record(" narrowMostSpecific" )
1806
1813
alts match {
1807
- case Nil => alts
1808
- case _ :: Nil => alts
1814
+ case Nil | _ :: Nil => alts
1809
1815
case alt1 :: alt2 :: Nil =>
1810
1816
compare(alt1, alt2) match {
1811
1817
case 1 => alt1 :: Nil
@@ -1937,6 +1943,15 @@ trait Applications extends Compatibility {
1937
1943
else resolve(alts)
1938
1944
end resolveOverloaded
1939
1945
1946
+ def isApplicableTerm (argTypes : List [Type ], resultType : Type , argMatch : ArgMatch )(using Context ): TermRef => Boolean =
1947
+ onMethod(_, argTypes.nonEmpty):
1948
+ isApplicableMethodRef(_, argTypes, resultType, argMatch)
1949
+
1950
+ def isApplicableTerm (argTypes : List [Tree ], resultType : Type , keepConstraint : Boolean , argMatch : ArgMatch )(using Context ): TermRef => Boolean =
1951
+ onMethod(_, argTypes.nonEmpty):
1952
+ isApplicableMethodRef(_, argTypes, resultType, keepConstraint, argMatch)
1953
+
1954
+
1940
1955
/** This private version of `resolveOverloaded` does the bulk of the work of
1941
1956
* overloading resolution, but does neither result adaptation nor apply insertion.
1942
1957
* It might be called twice from the public `resolveOverloaded` method, once with
@@ -1972,7 +1987,8 @@ trait Applications extends Compatibility {
1972
1987
}
1973
1988
1974
1989
def narrowByTypes (alts : List [TermRef ], argTypes : List [Type ], resultType : Type ): List [TermRef ] =
1975
- alts.filterConserve(isApplicableMethodRef(_, argTypes, resultType, ArgMatch .CompatibleCAP ))
1990
+ alts.filterConserve:
1991
+ isApplicableTerm(argTypes, resultType, ArgMatch .CompatibleCAP )
1976
1992
1977
1993
/** Normalization steps before checking arguments:
1978
1994
*
@@ -2047,9 +2063,8 @@ trait Applications extends Compatibility {
2047
2063
alts
2048
2064
2049
2065
def narrowByTrees (alts : List [TermRef ], args : List [Tree ], resultType : Type ): List [TermRef ] =
2050
- alts.filterConserve(alt =>
2051
- isApplicableMethodRef(alt, args, resultType, keepConstraint = false , ArgMatch .CompatibleCAP )
2052
- )
2066
+ alts.filterConserve:
2067
+ isApplicableTerm(args, resultType, keepConstraint = false , ArgMatch .CompatibleCAP )
2053
2068
2054
2069
record(" resolveOverloaded.FunProto" , alts.length)
2055
2070
val alts1 = narrowBySize(alts)
0 commit comments