diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index def6fac0556e..36c211b2110c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -4364,6 +4364,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer else formals1 implicitArgs(formals2, argIndex + 1, pt) + val pt1 = pt.deepenProtoTrans + val approxPt = withMode(Mode.TypevarsMissContext): + wildApprox(pt1) + val containsUninst = new TypeAccumulator[Boolean]: + def apply(need: Boolean, tp: Type): Boolean = + need || tp.match + case tvar: TypeVar => + ctx.typerState.constraint.contains(tvar) || tvar.instanceOpt.isInstanceOf[TypeVar] + case _ => + foldOver(need, tp) + if (pt1 `ne` pt) + && (pt1 ne sharpenedPt) + && (AvoidWildcardsMap()(approxPt) `eq` approxPt) + && !isFullyDefined(formal, ForceDegree.none) + && !containsUninst(false, formal) then + constrainResult(tree.symbol, wtp, pt1) val arg = inferImplicitArg(formal, tree.span.endPos) lazy val defaultArg = findDefaultArgument(argIndex) @@ -4389,7 +4405,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer arg.tpe match case failed: SearchFailureType if canProfitFromMoreConstraints => - val pt1 = pt.deepenProtoTrans if (pt1 `ne` pt) && (pt1 ne sharpenedPt) && tryConstrainResult(pt1) then return implicitArgs(formals, argIndex, pt1) case _ =>