Skip to content

Commit 3ce6938

Browse files
committed
GADTs: freeze when joining LHS union
These approximations shouldn't be used to derive GADTs constraints, just as the .widenSingleton approx shouldn't.
1 parent 5dded52 commit 3ce6938

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
442442
// type parameter, we will instantiate `C` to `A` and then fail when comparing
443443
// with `B[Y]`. To do the right thing, we need to instantiate `C` to the
444444
// common superclass of `A` and `B`.
445-
recur(tp1.join, tp2)
445+
inFrozenGadt { recur(tp1.join, tp2) }
446446
case _ =>
447447
false
448448
}
@@ -469,7 +469,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
469469
widenOK
470470
|| joinOK
471471
|| (tp1.isSoft || constrainRHSVars(tp2)) && recur(tp11, tp2) && recur(tp12, tp2)
472-
|| containsAnd(tp1) && recur(tp1.join, tp2)
472+
|| containsAnd(tp1) && inFrozenGadt { isSubType(tp1.join, tp2, approx) }
473473
case tp1: MatchType =>
474474
val reduced = tp1.reduced
475475
if (reduced.exists) recur(reduced, tp2) else thirdTry

0 commit comments

Comments
 (0)