@@ -533,15 +533,17 @@ trait Applications extends Compatibility {
533533 case formal :: formals1 =>
534534
535535 /** Add result of typing argument `arg` against parameter type `formal`.
536- * @return A type transformation to apply to all arguments following this one.
536+ * @return The remaining formal parameter types. If the method is parameter-dependent
537+ * this means substituting the actual argument type for the current formal parameter
538+ * in the remaining formal parameters.
537539 */
538- def addTyped (arg : Arg , formal : Type ): Type => Type = {
540+ def addTyped (arg : Arg , formal : Type ): List [ Type ] =
539541 addArg(typedArg(arg, formal), formal)
540- if ( methodType.isParamDependent && typeOfArg(arg).exists)
542+ if methodType.isParamDependent && typeOfArg(arg).exists then
541543 // `typeOfArg(arg)` could be missing because the evaluation of `arg` produced type errors
542- safeSubstParam(_, methodType.paramRefs(n), typeOfArg(arg))
543- else identity
544- }
544+ formals1.mapconserve( safeSubstParam(_, methodType.paramRefs(n), typeOfArg(arg) ))
545+ else
546+ formals1
545547
546548 def missingArg (n : Int ): Unit = {
547549 val pname = methodType.paramNames(n)
@@ -553,7 +555,7 @@ trait Applications extends Compatibility {
553555 def tryDefault (n : Int , args1 : List [Arg ]): Unit = {
554556 val sym = methRef.symbol
555557
556- val defaultExpr =
558+ val defaultArg =
557559 if (isJavaAnnotConstr(sym)) {
558560 val cinfo = sym.owner.asClass.classInfo
559561 val pname = methodType.paramNames(n)
@@ -580,10 +582,12 @@ trait Applications extends Compatibility {
580582 EmptyTree
581583 }
582584
583- if (! defaultExpr.isEmpty) {
584- val substParam = addTyped(treeToArg(defaultExpr), formal)
585- matchArgs(args1, formals1.mapconserve(substParam), n + 1 )
586- }
585+ def implicitArg = implicitArgTree(formal, appPos.span)
586+
587+ if ! defaultArg.isEmpty then
588+ matchArgs(args1, addTyped(treeToArg(defaultArg), formal), n + 1 )
589+ else if methodType.isContextualMethod && ctx.mode.is(Mode .ImplicitsEnabled ) then
590+ matchArgs(args1, addTyped(treeToArg(implicitArg), formal), n + 1 )
587591 else
588592 missingArg(n)
589593 }
@@ -605,8 +609,7 @@ trait Applications extends Compatibility {
605609 case EmptyTree :: args1 =>
606610 tryDefault(n, args1)
607611 case arg :: args1 =>
608- val substParam = addTyped(arg, formal)
609- matchArgs(args1, formals1.mapconserve(substParam), n + 1 )
612+ matchArgs(args1, addTyped(arg, formal), n + 1 )
610613 case nil =>
611614 tryDefault(n, args)
612615 }
@@ -1674,10 +1677,7 @@ trait Applications extends Compatibility {
16741677 pt match
16751678 case pt : FunProto =>
16761679 if pt.applyKind == ApplyKind .Using then
1677- val alts0 = alts.filterConserve { alt =>
1678- val mt = alt.widen.stripPoly
1679- mt.isImplicitMethod || mt.isContextualMethod
1680- }
1680+ val alts0 = alts.filterConserve(_.widen.stripPoly.isImplicitMethod)
16811681 if alts0 ne alts then return resolve(alts0)
16821682 else if alts.exists(_.widen.stripPoly.isContextualMethod) then
16831683 return resolveMapped(alts, alt => stripImplicit(alt.widen), pt)
0 commit comments