@@ -3869,12 +3869,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
38693869
38703870 def addImplicitArgs (using Context ) =
38713871 def hasDefaultParams = methPart(tree).symbol.hasDefaultParams
3872- def findDefaultArgument (argIndex : Int ): Tree =
3873- def appPart (t : Tree ): Tree = t match
3874- case Block (_, expr) => appPart(expr)
3875- case Inlined (_, _, expr) => appPart(expr)
3876- case t => t
3877- defaultArgument(appPart(tree), n = argIndex, testOnly = false )
38783872 def implicitArgs (formals : List [Type ], argIndex : Int , pt : Type ): List [Tree ] = formals match
38793873 case Nil => Nil
38803874 case formal :: formals1 =>
@@ -3890,17 +3884,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
38903884
38913885 val arg = inferImplicitArg(formal, tree.span.endPos)
38923886
3893- lazy val defaultArg = findDefaultArgument(argIndex)
3894- .showing(i " default argument: for $formal, $tree, $argIndex = $result" , typr)
3895- def argHasDefault = hasDefaultParams && ! defaultArg.isEmpty
3896-
38973887 def canProfitFromMoreConstraints =
38983888 arg.tpe.isInstanceOf [AmbiguousImplicits ]
3899- // Ambiguity could be decided by more constraints
3900- || ! isFullyDefined(formal, ForceDegree .none) && ! argHasDefault
3901- // More context might constrain type variables which could make implicit scope larger.
3902- // But in this case we should search with additional arguments typed only if there
3903- // is no default argument.
3889+ // ambiguity could be decided by more constraints
3890+ || ! isFullyDefined(formal, ForceDegree .none)
3891+ // more context might constrain type variables which could make implicit scope larger
39043892
39053893 arg.tpe match
39063894 case failed : SearchFailureType if canProfitFromMoreConstraints =>
@@ -3913,7 +3901,20 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
39133901 case failed : AmbiguousImplicits =>
39143902 arg :: implicitArgs(formals1, argIndex + 1 , pt)
39153903 case failed : SearchFailureType =>
3916- if argHasDefault then
3904+ lazy val defaultArg =
3905+ def appPart (t : Tree ): Tree = t match
3906+ case Block (stats, expr) => appPart(expr)
3907+ case Inlined (_, _, expr) => appPart(expr)
3908+ case _ => t
3909+ defaultArgument(appPart(tree), argIndex, testOnly = false )
3910+ .showing(i " default argument: for $formal, $tree, $argIndex = $result" , typr)
3911+ if ! hasDefaultParams || defaultArg.isEmpty then
3912+ // no need to search further, the adapt fails in any case
3913+ // the reason why we continue inferring arguments in case of an AmbiguousImplicits
3914+ // is that we need to know whether there are further errors.
3915+ // If there are none, we have to propagate the ambiguity to the caller.
3916+ arg :: formals1.map(dummyArg)
3917+ else
39173918 // This is tricky. On the one hand, we need the defaultArg to
39183919 // correctly type subsequent formal parameters in the same using
39193920 // clause in case there are parameter dependencies. On the other hand,
@@ -3924,12 +3925,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
39243925 // `if propFail.exists` where we re-type the whole using clause with named
39253926 // arguments for all implicits that were found.
39263927 arg :: inferArgsAfter(defaultArg)
3927- else
3928- // no need to search further, the adapt fails in any case
3929- // the reason why we continue inferring arguments in case of an AmbiguousImplicits
3930- // is that we need to know whether there are further errors.
3931- // If there are none, we have to propagate the ambiguity to the caller.
3932- arg :: formals1.map(dummyArg)
39333928 case _ =>
39343929 arg :: inferArgsAfter(arg)
39353930 end implicitArgs
0 commit comments