Skip to content

Commit ec1d6f5

Browse files
committed
Fix #12485: Avoid cycles in testing feasibility of exhaustivity check
This is a regression introduced in #12377.
1 parent b559209 commit ec1d6f5

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -793,23 +793,27 @@ class SpaceEngine(using Context) extends SpaceLogic {
793793
private def exhaustivityCheckable(sel: Tree): Boolean = {
794794
// Possible to check everything, but be compatible with scalac by default
795795
def isCheckable(tp: Type): Boolean =
796-
!tp.hasAnnotation(defn.UncheckedAnnot) && {
797-
val tpw = tp.widen.dealias
796+
val tpw = tp.widen.dealias
797+
val classSym = tpw.classSymbol
798+
classSym.is(Sealed) ||
799+
tpw.isInstanceOf[OrType] ||
800+
(tpw.isInstanceOf[AndType] && {
801+
val and = tpw.asInstanceOf[AndType]
802+
isCheckable(and.tp1) || isCheckable(and.tp2)
803+
}) ||
804+
tpw.isRef(defn.BooleanClass) ||
805+
classSym.isAllOf(JavaEnumTrait)
806+
807+
val res = !sel.tpe.hasAnnotation(defn.UncheckedAnnot) && {
808+
ctx.settings.YcheckAllPatmat.value
809+
|| isCheckable(sel.tpe)
810+
|| {
811+
val tpw = sel.tpe.widen.dealias
798812
val classSym = tpw.classSymbol
799-
ctx.settings.YcheckAllPatmat.value ||
800-
classSym.is(Sealed) ||
801-
tpw.isInstanceOf[OrType] ||
802-
(tpw.isInstanceOf[AndType] && {
803-
val and = tpw.asInstanceOf[AndType]
804-
isCheckable(and.tp1) || isCheckable(and.tp2)
805-
}) ||
806-
tpw.isRef(defn.BooleanClass) ||
807-
classSym.isAllOf(JavaEnumTrait) ||
808-
(defn.isProductSubType(tpw) && classSym.is(Case)
809-
&& productSelectorTypes(tpw, sel.srcPos).exists(isCheckable(_)))
813+
classSym.is(Case) && productSelectorTypes(tpw, sel.srcPos).exists(isCheckable(_))
810814
}
815+
}
811816

812-
val res = isCheckable(sel.tpe)
813817
debug.println(s"exhaustivity checkable: ${sel.show} = $res")
814818
res
815819
}

tests/patmat/i12485.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
case class A(a: A)
2+
3+
def foo(x: A) = x match
4+
case A(a) =>

0 commit comments

Comments
 (0)