diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 0df81f756925..57ecf0df33ad 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -619,7 +619,7 @@ object SpaceEngine { case OrType(tp1, tp2) => List(tp1, tp2) case tp if tp.isRef(defn.BooleanClass) => List(ConstantType(Constant(true)), ConstantType(Constant(false))) case tp if tp.isRef(defn.UnitClass) => ConstantType(Constant(())) :: Nil - case tp @ NamedType(Parts(parts), _) => parts.map(tp.derivedSelect) + case tp @ NamedType(Parts(parts), _) => if parts.exists(_ eq tp) then ListOfNoType else parts.map(tp.derivedSelect) case _: SingletonType => ListOfNoType case tp if tp.classSymbol.isAllOf(JavaEnum) => tp.classSymbol.children.map(_.termRef) // the class of a java enum value is the enum class, so this must follow SingletonType to not loop infinitely diff --git a/tests/pos/i19031.ci-reg1.scala b/tests/warn/i19031.ci-reg1.scala similarity index 91% rename from tests/pos/i19031.ci-reg1.scala rename to tests/warn/i19031.ci-reg1.scala index 3c15a3eb9afc..6e8c92c377ea 100644 --- a/tests/pos/i19031.ci-reg1.scala +++ b/tests/warn/i19031.ci-reg1.scala @@ -1,5 +1,3 @@ -//> using options -Werror - sealed trait Mark[T] trait Foo[T] diff --git a/tests/pos/i19031.ci-reg2.scala b/tests/warn/i19031.ci-reg2.scala similarity index 91% rename from tests/pos/i19031.ci-reg2.scala rename to tests/warn/i19031.ci-reg2.scala index e5b12cc17655..a4d5a83fa4dd 100644 --- a/tests/pos/i19031.ci-reg2.scala +++ b/tests/warn/i19031.ci-reg2.scala @@ -1,5 +1,3 @@ -//> using options -Werror - trait Outer: sealed trait Foo case class Bar1() extends Foo diff --git a/tests/pos/i19031.scala b/tests/warn/i19031.scala similarity index 80% rename from tests/pos/i19031.scala rename to tests/warn/i19031.scala index e56744017255..174f459460fd 100644 --- a/tests/pos/i19031.scala +++ b/tests/warn/i19031.scala @@ -1,5 +1,3 @@ -//> using options -Werror - sealed trait A: class B extends A diff --git a/tests/warn/i19031b.scala b/tests/warn/i19031b.scala new file mode 100644 index 000000000000..0b6eaff5df1f --- /dev/null +++ b/tests/warn/i19031b.scala @@ -0,0 +1,10 @@ +sealed trait A: + class B extends A + +class C extends A + +class Test: + def t1(a: A): Boolean = + a match + case b: A#B => true + case c: C => true