@@ -1437,10 +1437,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1437
1437
wtp.paramTypes.foreach(instantiateSelected(_, tvarsToInstantiate))
1438
1438
val constr = ctx.typerState.constraint
1439
1439
def addImplicitArgs = {
1440
- def implicitArgError (msg : => String ): Tree = {
1441
- ctx.error(msg, tree.pos.endPos)
1440
+ val errors = new mutable.ListBuffer [() => String ]
1441
+ def implicitArgError (msg : => String ) = {
1442
+ errors += (() => msg)
1442
1443
EmptyTree
1443
1444
}
1445
+ def issueErrors () = {
1446
+ for (err <- errors) ctx.error(err(), tree.pos.endPos)
1447
+ tree
1448
+ }
1444
1449
val args = (wtp.paramNames, wtp.paramTypes).zipped map { (pname, formal) =>
1445
1450
def where = d " parameter $pname of $methodStr"
1446
1451
inferImplicit(formal, EmptyTree , tree.pos.endPos) match {
@@ -1452,12 +1457,27 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1452
1457
implicitArgError(d " no implicit argument of type $formal found for $where" + failure.postscript)
1453
1458
}
1454
1459
}
1455
- if (args.exists(_.isEmpty) ) {
1460
+ if (errors.nonEmpty ) {
1456
1461
// If there are several arguments, some arguments might already
1457
- // have influenced the context, binfing variables, but later ones
1462
+ // have influenced the context, binding variables, but later ones
1458
1463
// might fail. In that case the constraint needs to be reset.
1459
1464
ctx.typerState.constraint = constr
1460
- tree
1465
+
1466
+ // If method has default params, fall back to regular application
1467
+ // where all inferred implicits are passed as named args.
1468
+ if (tree.symbol.hasDefaultParams) {
1469
+ val namedArgs = (wtp.paramNames, args).zipped.flatMap { (pname, arg) =>
1470
+ arg match {
1471
+ case EmptyTree => Nil
1472
+ case _ => untpd.NamedArg (pname, untpd.TypedSplice (arg)) :: Nil
1473
+ }
1474
+ }
1475
+ tryEither { implicit ctx =>
1476
+ typed(untpd.Apply (untpd.TypedSplice (tree), namedArgs), pt)
1477
+ } { (_, _) =>
1478
+ issueErrors()
1479
+ }
1480
+ } else issueErrors()
1461
1481
}
1462
1482
else adapt(tpd.Apply (tree, args), pt)
1463
1483
}
0 commit comments