Skip to content

Commit

Permalink
Restrict widening MatchTypes to its bounds
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dwijnand committed May 24, 2023
1 parent f7da93d commit 09f5e4c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
tp1.cases.corresponds(tp2.cases)(isSubType)
case _ => false
}
recur(tp1.underlying, tp2) || compareMatch
(!caseLambda.exists || canWidenAbstract) && recur(tp1.underlying, tp2) || compareMatch
case tp1: AnnotatedType if tp1.isRefining =>
isNewSubType(tp1.parent)
case JavaArrayType(elem1) =>
Expand Down

0 comments on commit 09f5e4c

Please sign in to comment.