Skip to content

Commit 487d2ae

Browse files
committed
Refine treatment of apply members in overloading resolution
Consider apply members in overloading resolution only if arguments are passed
1 parent 989163e commit 487d2ae

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,29 +1180,34 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
11801180
* @param resultType The expected result type of the application
11811181
*/
11821182
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))
1183+
onMethod(tp, targs.nonEmpty || args.nonEmpty) {
1184+
isApplicableMethodRef(_, targs, args, resultType, keepConstraint)
1185+
}
11841186

11851187
/** Is given type applicable to argument types `args`, possibly after inserting an `apply`?
11861188
* @param resultType The expected result type of the application
11871189
*/
11881190
def isApplicableType(tp: Type, args: List[Type], resultType: Type)(implicit ctx: Context): Boolean =
1189-
onMethod(tp, isApplicableMethodRef(_, args, resultType))
1191+
onMethod(tp, args.nonEmpty) {
1192+
isApplicableMethodRef(_, args, resultType)
1193+
}
11901194

11911195
/** Is given method type applicable to type arguments `targs` and argument trees `args` without inferring views,
11921196
* possibly after inserting an `apply`?
11931197
* @param resultType The expected result type of the application
11941198
*/
11951199
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))
1200+
onMethod(tp, targs.nonEmpty || args.nonEmpty) { methRef =>
1201+
ctx.test(implicit ctx => new ApplicableToTreesDirectly(methRef, targs, args, resultType).success)
1202+
}
11981203

1199-
private def onMethod(tp: Type, p: TermRef => Boolean)(implicit ctx: Context): Boolean = tp match {
1204+
private def onMethod(tp: Type, followApply: Boolean)(p: TermRef => Boolean)(implicit ctx: Context): Boolean = tp match {
12001205
case methRef: TermRef if methRef.widenSingleton.isInstanceOf[MethodicType] =>
12011206
p(methRef)
12021207
case mt: MethodicType =>
12031208
p(mt.narrow)
12041209
case _ =>
1205-
tp.member(nme.apply).hasAltWith(d => p(TermRef(tp, nme.apply, d)))
1210+
followApply && tp.member(nme.apply).hasAltWith(d => p(TermRef(tp, nme.apply, d)))
12061211
}
12071212

12081213
/** Does `tp` have an extension method named `name` with this-argument `argType` and
@@ -1564,7 +1569,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
15641569
else if (numParams > numArgs + 1) hasDefault
15651570
else isVarArgs || hasDefault
15661571
case tp =>
1567-
numArgs == 0 || onMethod(tp, sizeFits)
1572+
numArgs == 0 || onMethod(tp, followApply = true)(sizeFits)
15681573
}
15691574

15701575
def narrowBySize(alts: List[TermRef]): List[TermRef] =

0 commit comments

Comments
 (0)