@@ -54,7 +54,6 @@ import transform.CheckUnused.OriginalName
5454import scala .annotation .{unchecked as _ , * }
5555import dotty .tools .dotc .util .chaining .*
5656import dotty .tools .dotc .ast .untpd .Mod
57- import dotty .tools .dotc .reporting .Reporter .NoReporter
5857
5958object Typer {
6059
@@ -4358,33 +4357,25 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43584357 else formals1
43594358 implicitArgs(formals2, argIndex + 1 , pt)
43604359
4361-
4362- def doesntContainsWildcards = {
4363- val newCtx = ctx.fresh.setNewScope.setReporter(new reporting.ThrowingReporter (NoReporter ))
4364- val substCtxMap = new TypeMap ():
4365- def apply (tp : Type ): Type = tp match
4366- case tp : FunProto => mapOver(
4367- tp.derivedFunProto(resultType = tp.resultType(using newCtx)).withContext(newCtx)
4368- )
4369- case tp => mapOver(tp)
4370- val pt1 = substCtxMap(pt.deepenProtoTrans(using newCtx))
4371- try {
4372- ! pt1.containsWildcardTypes(using newCtx)
4373- } catch {
4374- case _ : UnhandledError => false
4375- }
4376- }
43774360 val pt1 = pt.deepenProtoTrans
4361+ val approxPt = withMode(Mode .TypevarsMissContext ):
4362+ wildApprox(pt1)
4363+ var formalConstrained = false
4364+ val tm = new TypeMap :
4365+ def apply (t : Type ): Type = t match
4366+ case tvar : TypeVar =>
4367+ formalConstrained |= ctx.typerState.constraint.contains(tvar) || tvar.instanceOpt.isInstanceOf [TypeVar ]
4368+ tvar
4369+ case _ =>
4370+ if formalConstrained then t
4371+ else mapOver(t)
4372+ tm(formal)
43784373 if (pt1 `ne` pt)
43794374 && (pt1 ne sharpenedPt)
4380- && formal.typeSymbol != defn. ClassTagClass
4375+ && ( AvoidWildcardsMap ()(approxPt) `eq` approxPt)
43814376 && ! isFullyDefined(formal, ForceDegree .none)
4382- && ! formal.existsPart(ty => {
4383- val dty = ty.dealias
4384- (dty ne ty) && ty.isInstanceOf [TypeVar ] && dty.isInstanceOf [TypeVar ]
4385- }, StopAt .Static , forceLazy = false )
4386- && doesntContainsWildcards then
4387- withoutMode(Mode .ImplicitsEnabled )(constrainResult(tree.symbol, wtp, wildApprox(pt1)))
4377+ && ! formalConstrained then
4378+ constrainResult(tree.symbol, wtp, pt1)
43884379 val arg = inferImplicitArg(formal, tree.span.endPos)
43894380
43904381 def canProfitFromMoreConstraints =
0 commit comments