@@ -1163,36 +1163,38 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1163
1163
/** Is given method reference applicable to type arguments `targs` and argument trees `args`?
1164
1164
* @param resultType The expected result type of the application
1165
1165
*/
1166
- def isApplicable (methRef : TermRef , targs : List [Type ], args : List [Tree ], resultType : Type , keepConstraint : Boolean )(implicit ctx : Context ): Boolean = {
1166
+ def isApplicableMethodRef (methRef : TermRef , targs : List [Type ], args : List [Tree ], resultType : Type , keepConstraint : Boolean )(implicit ctx : Context ): Boolean = {
1167
1167
def isApp (implicit ctx : Context ): Boolean =
1168
1168
new ApplicableToTrees (methRef, targs, args, resultType).success
1169
1169
if (keepConstraint) isApp else ctx.test(implicit ctx => isApp)
1170
1170
}
1171
1171
1172
- /** Is given method reference applicable to type arguments `targs` and argument trees `args` without inferring views?
1173
- * @param resultType The expected result type of the application
1174
- */
1175
- def isDirectlyApplicable (methRef : TermRef , targs : List [Type ], args : List [Tree ], resultType : Type )(implicit ctx : Context ): Boolean =
1176
- ctx.test(implicit ctx => new ApplicableToTreesDirectly (methRef, targs, args, resultType).success)
1177
-
1178
1172
/** Is given method reference applicable to argument types `args`?
1179
1173
* @param resultType The expected result type of the application
1180
1174
*/
1181
- def isApplicable (methRef : TermRef , args : List [Type ], resultType : Type )(implicit ctx : Context ): Boolean =
1175
+ def isApplicableMethodRef (methRef : TermRef , args : List [Type ], resultType : Type )(implicit ctx : Context ): Boolean =
1182
1176
ctx.test(implicit ctx => new ApplicableToTypes (methRef, args, resultType).success)
1183
1177
1184
1178
/** Is given type applicable to type arguments `targs` and argument trees `args`,
1185
1179
* possibly after inserting an `apply`?
1186
1180
* @param resultType The expected result type of the application
1187
1181
*/
1188
- def isApplicable (tp : Type , targs : List [Type ], args : List [Tree ], resultType : Type , keepConstraint : Boolean )(implicit ctx : Context ): Boolean =
1189
- onMethod(tp, isApplicable (_, targs, args, resultType, keepConstraint))
1182
+ def isApplicableType (tp : Type , targs : List [Type ], args : List [Tree ], resultType : Type , keepConstraint : Boolean )(implicit ctx : Context ): Boolean =
1183
+ onMethod(tp, isApplicableMethodRef (_, targs, args, resultType, keepConstraint))
1190
1184
1191
1185
/** Is given type applicable to argument types `args`, possibly after inserting an `apply`?
1192
1186
* @param resultType The expected result type of the application
1193
1187
*/
1194
- def isApplicable (tp : Type , args : List [Type ], resultType : Type )(implicit ctx : Context ): Boolean =
1195
- onMethod(tp, isApplicable(_, args, resultType))
1188
+ def isApplicableType (tp : Type , args : List [Type ], resultType : Type )(implicit ctx : Context ): Boolean =
1189
+ onMethod(tp, isApplicableMethodRef(_, args, resultType))
1190
+
1191
+ /** Is given method type applicable to type arguments `targs` and argument trees `args` without inferring views,
1192
+ * possibly after inserting an `apply`?
1193
+ * @param resultType The expected result type of the application
1194
+ */
1195
+ def isDirectlyApplicableType (tp : Type , targs : List [Type ], args : List [Tree ], resultType : Type )(implicit ctx : Context ): Boolean =
1196
+ onMethod(tp, methRef =>
1197
+ ctx.test(implicit ctx => new ApplicableToTreesDirectly (methRef, targs, args, resultType).success))
1196
1198
1197
1199
private def onMethod (tp : Type , p : TermRef => Boolean )(implicit ctx : Context ): Boolean = tp match {
1198
1200
case methRef : TermRef if methRef.widenSingleton.isInstanceOf [MethodicType ] =>
@@ -1208,7 +1210,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1208
1210
*/
1209
1211
def hasExtensionMethod (tp : Type , name : TermName , argType : Type , resultType : Type )(implicit ctx : Context ) = {
1210
1212
def qualifies (mbr : Denotation ) =
1211
- mbr.exists && isApplicable (tp.select(name, mbr), argType :: Nil , resultType)
1213
+ mbr.exists && isApplicableType (tp.select(name, mbr), argType :: Nil , resultType)
1212
1214
tp.memberBasedOnFlags(name, required = ExtensionMethod ) match {
1213
1215
case mbr : SingleDenotation => qualifies(mbr)
1214
1216
case mbr => mbr.hasAltWith(qualifies(_))
@@ -1272,7 +1274,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1272
1274
val formals1 =
1273
1275
if (tp1.isVarArgsMethod && tp2.isVarArgsMethod) tp1.paramInfos.map(_.repeatedToSingle)
1274
1276
else tp1.paramInfos
1275
- isApplicable (alt2, formals1, WildcardType ) ||
1277
+ isApplicableMethodRef (alt2, formals1, WildcardType ) ||
1276
1278
tp1.paramInfos.isEmpty && tp2.isInstanceOf [LambdaType ]
1277
1279
case tp1 : PolyType => // (2)
1278
1280
val nestedCtx = ctx.fresh.setExploreTyperState()
@@ -1541,7 +1543,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1541
1543
}
1542
1544
1543
1545
def narrowByTypes (alts : List [TermRef ], argTypes : List [Type ], resultType : Type ): List [TermRef ] =
1544
- alts filter (isApplicable (_, argTypes, resultType))
1546
+ alts filter (isApplicableType (_, argTypes, resultType))
1545
1547
1546
1548
val candidates = pt match {
1547
1549
case pt @ FunProto (args, resultType) =>
@@ -1551,7 +1553,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1551
1553
case x => x
1552
1554
}
1553
1555
1554
- def sizeFits (alt : TermRef , tp : Type ): Boolean = tp .stripPoly match {
1556
+ def sizeFits (alt : TermRef ): Boolean = alt.widen .stripPoly match {
1555
1557
case tp : MethodType =>
1556
1558
val ptypes = tp.paramInfos
1557
1559
val numParams = ptypes.length
@@ -1561,12 +1563,12 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1561
1563
else if (numParams < numArgs) isVarArgs
1562
1564
else if (numParams > numArgs + 1 ) hasDefault
1563
1565
else isVarArgs || hasDefault
1564
- case _ =>
1565
- numArgs == 0
1566
+ case tp =>
1567
+ numArgs == 0 || onMethod(tp, sizeFits)
1566
1568
}
1567
1569
1568
1570
def narrowBySize (alts : List [TermRef ]): List [TermRef ] =
1569
- alts filter (alt => sizeFits(alt, alt.widen) )
1571
+ alts. filter( sizeFits)
1570
1572
1571
1573
def narrowByShapes (alts : List [TermRef ]): List [TermRef ] = {
1572
1574
if (normArgs exists untpd.isFunctionWithUnknownParamType)
@@ -1578,11 +1580,11 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1578
1580
1579
1581
def narrowByTrees (alts : List [TermRef ], args : List [Tree ], resultType : Type ): List [TermRef ] = {
1580
1582
val alts2 = alts.filter(alt =>
1581
- isDirectlyApplicable (alt, targs, args, resultType)
1583
+ isDirectlyApplicableType (alt, targs, args, resultType)
1582
1584
)
1583
1585
if (alts2.isEmpty && ! ctx.isAfterTyper)
1584
1586
alts.filter(alt =>
1585
- isApplicable (alt, targs, args, resultType, keepConstraint = false )
1587
+ isApplicableType (alt, targs, args, resultType, keepConstraint = false )
1586
1588
)
1587
1589
else
1588
1590
alts2
0 commit comments