@@ -3850,12 +3850,23 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
38503850 implicitArgs(formals2, argIndex + 1 , pt)
38513851
38523852 val arg = inferImplicitArg(formal, tree.span.endPos)
3853+
3854+ def canProfitFromMoreConstraints =
3855+ arg.tpe.isInstanceOf [AmbiguousImplicits ]
3856+ // ambiguity could be decided by more constraints
3857+ || ! isFullyDefined(formal, ForceDegree .none)
3858+ // more context might constrain type variables which could make implicit scope larger
3859+
38533860 arg.tpe match
3854- case failed : AmbiguousImplicits =>
3861+ case failed : SearchFailureType if canProfitFromMoreConstraints =>
38553862 val pt1 = pt.deepenProtoTrans
38563863 if (pt1 `ne` pt) && (pt1 ne sharpenedPt) && constrainResult(tree.symbol, wtp, pt1)
3857- then implicitArgs(formals, argIndex, pt1)
3858- else arg :: implicitArgs(formals1, argIndex + 1 , pt1)
3864+ then return implicitArgs(formals, argIndex, pt1)
3865+ case _ =>
3866+
3867+ arg.tpe match
3868+ case failed : AmbiguousImplicits =>
3869+ arg :: implicitArgs(formals1, argIndex + 1 , pt)
38593870 case failed : SearchFailureType =>
38603871 lazy val defaultArg =
38613872 def appPart (t : Tree ): Tree = t match
0 commit comments