Skip to content

Fix #12485: Avoid cycles in testing feasibility of exhaustivity check #12488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -793,23 +793,27 @@ class SpaceEngine(using Context) extends SpaceLogic {
private def exhaustivityCheckable(sel: Tree): Boolean = {
// Possible to check everything, but be compatible with scalac by default
def isCheckable(tp: Type): Boolean =
!tp.hasAnnotation(defn.UncheckedAnnot) && {
val tpw = tp.widen.dealias
val tpw = tp.widen.dealias
val classSym = tpw.classSymbol
classSym.is(Sealed) ||
tpw.isInstanceOf[OrType] ||
(tpw.isInstanceOf[AndType] && {
val and = tpw.asInstanceOf[AndType]
isCheckable(and.tp1) || isCheckable(and.tp2)
}) ||
tpw.isRef(defn.BooleanClass) ||
classSym.isAllOf(JavaEnumTrait)

val res = !sel.tpe.hasAnnotation(defn.UncheckedAnnot) && {
ctx.settings.YcheckAllPatmat.value
|| isCheckable(sel.tpe)
|| {
val tpw = sel.tpe.widen.dealias
val classSym = tpw.classSymbol
ctx.settings.YcheckAllPatmat.value ||
classSym.is(Sealed) ||
tpw.isInstanceOf[OrType] ||
(tpw.isInstanceOf[AndType] && {
val and = tpw.asInstanceOf[AndType]
isCheckable(and.tp1) || isCheckable(and.tp2)
}) ||
tpw.isRef(defn.BooleanClass) ||
classSym.isAllOf(JavaEnumTrait) ||
(defn.isProductSubType(tpw) && classSym.is(Case)
&& productSelectorTypes(tpw, sel.srcPos).exists(isCheckable(_)))
classSym.is(Case) && productSelectorTypes(tpw, sel.srcPos).exists(isCheckable(_))
}
}

val res = isCheckable(sel.tpe)
debug.println(s"exhaustivity checkable: ${sel.show} = $res")
res
}
Expand Down
4 changes: 4 additions & 0 deletions tests/patmat/i12485.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
case class A(a: A)

def foo(x: A) = x match
case A(a) =>