Skip to content

Commit c80fd34

Browse files
committed
Freeze constraint also for joinOK
1 parent 13ac94e commit c80fd34

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
166166
try op finally frozenGadt = savedFrozenGadt
167167
}
168168

169+
private inline def inFrozenGadtAndConstraint[T](inline op: T): T =
170+
inFrozenGadtIf(true)(inFrozenConstraint(op))
171+
169172
protected def isSubType(tp1: Type, tp2: Type, a: ApproxState): Boolean = {
170173
val savedApprox = approx
171174
val savedLeftRoot = leftRoot
@@ -431,25 +434,18 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
431434
case Some(b) => return b
432435
case None =>
433436

434-
/** `recur` shouldn't normally be used with approximated types, according to its
435-
* documentation. In the specific examples where this function is
436-
* called, it is sound to do so as long as we freeze GADTs.
437-
*/
438-
def recurInFrozenGadt(tp1: Type, tp2: Type) =
439-
inFrozenGadt { recur(tp1, tp2) }
440-
441437
def widenOK =
442438
(tp2.widenSingletons eq tp2)
443439
&& (tp1.widenSingletons ne tp1)
444-
&& inFrozenConstraint(recurInFrozenGadt(tp1.widenSingletons, tp2))
440+
&& inFrozenGadtAndConstraint(recur(tp1.widenSingletons, tp2))
445441

446442
def joinOK = tp2.dealiasKeepRefiningAnnots match {
447443
case tp2: AppliedType if !tp2.tycon.typeSymbol.isClass =>
448444
// If we apply the default algorithm for `A[X] | B[Y] <: C[Z]` where `C` is a
449445
// type parameter, we will instantiate `C` to `A` and then fail when comparing
450446
// with `B[Y]`. To do the right thing, we need to instantiate `C` to the
451447
// common superclass of `A` and `B`.
452-
recurInFrozenGadt(tp1.join, tp2)
448+
inFrozenGadtAndConstraint(recur(tp1.join, tp2))
453449
case _ =>
454450
false
455451
}
@@ -476,7 +472,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
476472
widenOK
477473
|| joinOK
478474
|| (tp1.isSoft || constrainRHSVars(tp2)) && recur(tp11, tp2) && recur(tp12, tp2)
479-
|| containsAnd(tp1) && recurInFrozenGadt(tp1.join, tp2)
475+
|| containsAnd(tp1) && inFrozenGadt(recur(tp1.join, tp2))
480476
case tp1: MatchType =>
481477
val reduced = tp1.reduced
482478
if (reduced.exists) recur(reduced, tp2) else thirdTry

0 commit comments

Comments
 (0)