Skip to content

Commit 09f5e4c

Browse files
committed
Restrict widening MatchTypes to its bounds
During match type reduction, if we're going to allow approximating we must further restrict match types from widening to its bound. Failing to do so will record GADT constraint bounds that parameters will be approximated to, which is lossy and leads to a loss of type checking completion.. For instance, in a variant of i13633 with an added `<: (Boolean, Boolean)` bound to `PlusTri`, when reducing `PlusTri[a, b, O] match { case (x, y) => ... }`, widening the expansion of `PlusTri[a, b, O]` to its bound `(Boolean, Boolean)`, causes the recording the constraints bounds `x >: Boolean` and `y >: Boolean` and then reduction instantiates `x` and `y` to Boolean, losing the precision that comes from `a`, `b`, and `O`. This came up while implementing bounds checking to match type case bodies, and requires an important fix to PatternTypeConstrainer (the use of typeSymbol's) so the tests that require this are part of that effort.
1 parent f7da93d commit 09f5e4c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
10111011
tp1.cases.corresponds(tp2.cases)(isSubType)
10121012
case _ => false
10131013
}
1014-
recur(tp1.underlying, tp2) || compareMatch
1014+
(!caseLambda.exists || canWidenAbstract) && recur(tp1.underlying, tp2) || compareMatch
10151015
case tp1: AnnotatedType if tp1.isRefining =>
10161016
isNewSubType(tp1.parent)
10171017
case JavaArrayType(elem1) =>

0 commit comments

Comments
 (0)