diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 61a7096ca781..36967e049b86 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -2879,7 +2879,9 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) { if (provablyEmpty(scrut)) NoType else - recur(cases) + val savedConstraint = constraint + try recur(cases) + finally constraint = savedConstraint // caseLambda additions are dropped } } } diff --git a/tests/neg/6697.check b/tests/neg/6697.check new file mode 100644 index 000000000000..b413e75e0d60 --- /dev/null +++ b/tests/neg/6697.check @@ -0,0 +1,14 @@ +-- [E057] Type Mismatch Error: tests/neg/6697.scala:6:35 --------------------------------------------------------------- +6 | type Copy[O <: Off] = Of[Sup[O], Sub[O]] // error + | ^ + | Type argument Test.Sub[O] does not conform to upper bound Test.Sup[O] + | + | Note: a match type could not be fully reduced: + | + | trying to reduce Test.Sub[O] + | failed since selector O + | matches none of the cases + | + | case Test.Of[sup, sub] => sub + +longer explanation available when compiling with `-explain` diff --git a/tests/pos/6697.scala b/tests/neg/6697.scala similarity index 79% rename from tests/pos/6697.scala rename to tests/neg/6697.scala index 18a59d5b61f4..bd3b30f8079b 100644 --- a/tests/pos/6697.scala +++ b/tests/neg/6697.scala @@ -3,5 +3,5 @@ object Test { case class Of[sup, sub <: sup]() extends Off type Sup[O <: Off] = O match { case Of[sup, sub] => sup } type Sub[O <: Off] = O match { case Of[sup, sub] => sub } - type Copy[O <: Off] = Of[Sup[O], Sub[O]] + type Copy[O <: Off] = Of[Sup[O], Sub[O]] // error } diff --git a/tests/neg/9107.scala b/tests/neg/9107.scala new file mode 100644 index 000000000000..a0cbabd50b4d --- /dev/null +++ b/tests/neg/9107.scala @@ -0,0 +1,14 @@ +trait M[F[_]] +trait Inv[T] + +object Test { + def ev[X] = implicitly[ + (X match { case Inv[t] => Int }) =:= + (X match { case Inv[t] => t }) + ] // error + + def ev2[X] = implicitly[ + (M[[t] =>> runtime.MatchCase[Inv[t], Int]]) =:= + (M[[t] =>> runtime.MatchCase[Inv[t], t]]) + ] // error +}