Skip to content

Commit e5b2e76

Browse files
committed
not constrain if formal contains constrained type vars
1 parent e8c4c10 commit e5b2e76

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4360,10 +4360,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43604360
val pt1 = pt.deepenProtoTrans
43614361
val approxPt = withMode(Mode.TypevarsMissContext):
43624362
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)
4368+
val inst = tvar.instanceOpt
4369+
if (inst.exists && !formalConstrained) mapOver(inst) else tvar
4370+
case _ =>
4371+
if formalConstrained then t
4372+
else mapOver(t)
4373+
tm(formal)
43634374
if (pt1 `ne` pt)
43644375
&& (pt1 ne sharpenedPt)
43654376
&& (AvoidWildcardsMap()(approxPt) `eq` approxPt)
4366-
&& !isFullyDefined(formal, ForceDegree.none) then
4377+
&& !isFullyDefined(formal, ForceDegree.none)
4378+
&& !formalConstrained then
43674379
constrainResult(tree.symbol, wtp, pt1)
43684380
val arg = inferImplicitArg(formal, tree.span.endPos)
43694381

0 commit comments

Comments
 (0)