Skip to content

Commit 976af59

Browse files
committed
use TypeAccumulator
1 parent 6a98e3a commit 976af59

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4367,21 +4367,18 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43674367
val pt1 = pt.deepenProtoTrans
43684368
val approxPt = withMode(Mode.TypevarsMissContext):
43694369
wildApprox(pt1)
4370-
var formalConstrained = false
4371-
val tm = new TypeMap:
4372-
def apply(t: Type): Type = t match
4373-
case tvar: TypeVar =>
4374-
formalConstrained |= ctx.typerState.constraint.contains(tvar) || tvar.instanceOpt.isInstanceOf[TypeVar]
4375-
tvar
4376-
case _ =>
4377-
if formalConstrained then t
4378-
else mapOver(t)
4379-
tm(formal)
4370+
val containsUninst = new TypeAccumulator[Boolean]:
4371+
def apply(need: Boolean, tp: Type): Boolean =
4372+
need || tp.match
4373+
case tvar: TypeVar =>
4374+
ctx.typerState.constraint.contains(tvar) || tvar.instanceOpt.isInstanceOf[TypeVar]
4375+
case _ =>
4376+
foldOver(need, tp)
43804377
if (pt1 `ne` pt)
43814378
&& (pt1 ne sharpenedPt)
43824379
&& (AvoidWildcardsMap()(approxPt) `eq` approxPt)
43834380
&& !isFullyDefined(formal, ForceDegree.none)
4384-
&& !formalConstrained then
4381+
&& !containsUninst(false, formal) then
43854382
constrainResult(tree.symbol, wtp, pt1)
43864383
val arg = inferImplicitArg(formal, tree.span.endPos)
43874384

0 commit comments

Comments
 (0)