diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index e1605c326a05..ed610a7cedb6 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -1198,6 +1198,14 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling case _ => false } && { GADTused = true; true } + def tryGadtAnd1: Boolean = + ctx.mode.is(Mode.GadtConstraintInference) && { + tp1 match + case AndType(tp11, tp12) => + either(recur(tp11, tp2), recur(tp12, tp2)) + case _ => false + } + tycon2 match { case param2: TypeParamRef => isMatchingApply(tp1) || @@ -1213,6 +1221,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling case info2: ClassInfo => tycon2.name.startsWith("Tuple") && defn.isTupleNType(tp2) && recur(tp1, tp2.toNestedPairs) || + tryGadtAnd1 || tryBaseType(info2.cls) case _ => fourthTry diff --git a/tests/neg/i11545.scala b/tests/neg/i11545.scala new file mode 100644 index 000000000000..27f4b4f4b559 --- /dev/null +++ b/tests/neg/i11545.scala @@ -0,0 +1,21 @@ +// Taken from +// https://github.com/lampepfl/dotty/issues/11545#issuecomment-787609144 +class test0 { + type AA + trait S[A] + trait Inv[A] + + class P[X] extends S[Inv[X] & AA] + +} + +@main def test: Unit = + new test0: + type AA = Inv[String] + + def patmat[A, Y](s: S[Inv[A] & Y]): A = s match { + case p: P[x] => + "Hello" // error + } + + val got: Int = patmat[Int, AA](new P)