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