Skip to content

Commit

Permalink
Short-circuit isCheckable with classSymbol
Browse files Browse the repository at this point in the history
A mutually recursive, and ever-growing type pair like ExprMap and EM (in
the test case) would blow up isCheckable.  Let's use the classSymbol
instead.

[Cherry-picked eff3424]
  • Loading branch information
dwijnand authored and WojciechMazur committed Jul 1, 2024
1 parent f5d9cce commit 282a621
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ object SpaceEngine {
}

private def exhaustivityCheckable(sel: Tree)(using Context): Boolean = {
val seen = collection.mutable.Set.empty[Type]
val seen = collection.mutable.Set.empty[Symbol]

// Possible to check everything, but be compatible with scalac by default
def isCheckable(tp: Type): Boolean =
Expand All @@ -791,7 +791,7 @@ object SpaceEngine {
tpw.isRef(defn.BooleanClass) ||
classSym.isAllOf(JavaEnumTrait) ||
classSym.is(Case) && {
if seen.add(tpw) then productSelectorTypes(tpw, sel.srcPos).exists(isCheckable(_))
if seen.add(classSym) then productSelectorTypes(tpw, sel.srcPos).exists(isCheckable(_))
else true // recursive case class: return true and other members can still fail the check
}

Expand Down
12 changes: 12 additions & 0 deletions tests/pos/i19433.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// minimised from github.com/Adam-Vandervorst/CZ2

import scala.collection.mutable

private trait EMImpl[V, F[_]]

case class EM[V2](apps: ExprMap[ExprMap[V2]]) extends EMImpl[V2, EM]:
def collect[W](pf: PartialFunction[V2, W]): Unit =
val apps1 = apps.collect(_.collect(pf))

case class ExprMap[V](var em: EM[V] = null) extends EMImpl[V, ExprMap]:
def collect[W](pf: PartialFunction[V, W]): ExprMap[W] = ??? // was: StackOverflow in isCheckable

0 comments on commit 282a621

Please # to comment.