@@ -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,29 @@ 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 = false
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
+ ok = true
382
+ initWith(stripImplicit(methType))
383
+
361
384
/** The application was successful */
362
385
def success : Boolean = ok
363
386
@@ -688,6 +711,12 @@ trait Applications extends Compatibility {
688
711
private var typedArgBuf = new mutable.ListBuffer [Tree ]
689
712
private var liftedDefs : mutable.ListBuffer [Tree ] = null
690
713
private var myNormalizedFun : Tree = fun
714
+ override protected def reset (): Unit =
715
+ super .reset()
716
+ typedArgBuf = new mutable.ListBuffer [Tree ]
717
+ liftedDefs = null
718
+ myNormalizedFun = fun
719
+
691
720
init()
692
721
693
722
def addArg (arg : Tree , formal : Type ): Unit =
@@ -1299,6 +1328,16 @@ trait Applications extends Compatibility {
1299
1328
}
1300
1329
}
1301
1330
1331
+ /** Drop any implicit parameter section */
1332
+ def stripImplicit (tp : Type )(using Context ): Type = tp match {
1333
+ case mt : MethodType if mt.isImplicitMethod =>
1334
+ stripImplicit(resultTypeApprox(mt))
1335
+ case pt : PolyType =>
1336
+ pt.derivedLambdaType(pt.paramNames, pt.paramInfos, stripImplicit(pt.resultType))
1337
+ case _ =>
1338
+ tp
1339
+ }
1340
+
1302
1341
/** Compare owner inheritance level.
1303
1342
* @param sym1 The first owner
1304
1343
* @param sym2 The second owner
@@ -1466,16 +1505,6 @@ trait Applications extends Compatibility {
1466
1505
else tp
1467
1506
}
1468
1507
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
1508
def compareWithTypes (tp1 : Type , tp2 : Type ) = {
1480
1509
val ownerScore = compareOwner(alt1.symbol.maybeOwner, alt2.symbol.maybeOwner)
1481
1510
def winsType1 = isAsSpecific(alt1, tp1, alt2, tp2)
@@ -1901,7 +1930,7 @@ trait Applications extends Compatibility {
1901
1930
recur(altFormals.map(_.tail), args1)
1902
1931
case _ =>
1903
1932
}
1904
- recur(alts.map(_ .widen.firstParamTypes), pt.args)
1933
+ recur(alts.map(alt => stripImplicit(alt .widen) .firstParamTypes), pt.args)
1905
1934
}
1906
1935
1907
1936
private def harmonizeWith [T <: AnyRef ](ts : List [T ])(tpe : T => Type , adapt : (T , Type ) => T )(implicit ctx : Context ): List [T ] = {
0 commit comments