@@ -339,7 +339,7 @@ trait Applications extends Compatibility {
339
339
else
340
340
args
341
341
342
- protected def init ( ): Unit = methType match {
342
+ protected def initWith ( mt : Type ): Unit = mt match {
343
343
case methType : MethodType =>
344
344
// apply the result type constraint, unless method type is dependent
345
345
val resultApprox = resultTypeApprox(methType)
@@ -358,6 +358,28 @@ trait Applications extends Compatibility {
358
358
else fail(s " $methString does not take parameters " )
359
359
}
360
360
361
+ protected def reset (): Unit =
362
+ ok = true
363
+
364
+ /**
365
+ * This function tests whether a given method is applicable to the
366
+ * given arguments. Context parameters that precede the normal parameters
367
+ * pose problems for such a test. E.g.:
368
+
369
+ * def f(using String)(g: Int => String): Int
370
+ * f(x => "2")
371
+ * f(using summon[String])(x => "2")
372
+
373
+ * At the first call site, the context parameter is omitted. For the
374
+ * applicability test to pass in that case, we should also test
375
+ * the function `f` with its context parameters dropped.
376
+ */
377
+ protected def init (): Unit =
378
+ initWith(methType)
379
+ if ! success then
380
+ reset()
381
+ initWith(stripImplicit(methType))
382
+
361
383
/** The application was successful */
362
384
def success : Boolean = ok
363
385
@@ -688,6 +710,12 @@ trait Applications extends Compatibility {
688
710
private var typedArgBuf = new mutable.ListBuffer [Tree ]
689
711
private var liftedDefs : mutable.ListBuffer [Tree ] = null
690
712
private var myNormalizedFun : Tree = fun
713
+ override protected def reset (): Unit =
714
+ super .reset()
715
+ typedArgBuf = new mutable.ListBuffer [Tree ]
716
+ liftedDefs = null
717
+ myNormalizedFun = fun
718
+
691
719
init()
692
720
693
721
def addArg (arg : Tree , formal : Type ): Unit =
@@ -1299,6 +1327,16 @@ trait Applications extends Compatibility {
1299
1327
}
1300
1328
}
1301
1329
1330
+ /** Drop any implicit parameter section */
1331
+ def stripImplicit (tp : Type )(using Context ): Type = tp match {
1332
+ case mt : MethodType if mt.isImplicitMethod =>
1333
+ stripImplicit(resultTypeApprox(mt))
1334
+ case pt : PolyType =>
1335
+ pt.derivedLambdaType(pt.paramNames, pt.paramInfos, stripImplicit(pt.resultType))
1336
+ case _ =>
1337
+ tp
1338
+ }
1339
+
1302
1340
/** Compare owner inheritance level.
1303
1341
* @param sym1 The first owner
1304
1342
* @param sym2 The second owner
@@ -1466,16 +1504,6 @@ trait Applications extends Compatibility {
1466
1504
else tp
1467
1505
}
1468
1506
1469
- /** Drop any implicit parameter section */
1470
- def stripImplicit (tp : Type ): Type = tp match {
1471
- case mt : MethodType if mt.isImplicitMethod =>
1472
- stripImplicit(resultTypeApprox(mt))
1473
- case pt : PolyType =>
1474
- pt.derivedLambdaType(pt.paramNames, pt.paramInfos, stripImplicit(pt.resultType))
1475
- case _ =>
1476
- tp
1477
- }
1478
-
1479
1507
def compareWithTypes (tp1 : Type , tp2 : Type ) = {
1480
1508
val ownerScore = compareOwner(alt1.symbol.maybeOwner, alt2.symbol.maybeOwner)
1481
1509
def winsType1 = isAsSpecific(alt1, tp1, alt2, tp2)
@@ -1901,7 +1929,7 @@ trait Applications extends Compatibility {
1901
1929
recur(altFormals.map(_.tail), args1)
1902
1930
case _ =>
1903
1931
}
1904
- recur(alts.map(_ .widen.firstParamTypes), pt.args)
1932
+ recur(alts.map(alt => stripImplicit(alt .widen) .firstParamTypes), pt.args)
1905
1933
}
1906
1934
1907
1935
private def harmonizeWith [T <: AnyRef ](ts : List [T ])(tpe : T => Type , adapt : (T , Type ) => T )(implicit ctx : Context ): List [T ] = {
0 commit comments