Skip to content

Commit d9a0cd7

Browse files
dwijnandWojciechMazur
authored andcommitted
Short-circuit isCheckable with classSymbol
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]
1 parent 353a8b3 commit d9a0cd7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ object SpaceEngine {
775775
}
776776

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

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

tests/pos/i19433.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// minimised from github.com/Adam-Vandervorst/CZ2
2+
3+
import scala.collection.mutable
4+
5+
private trait EMImpl[V, F[_]]
6+
7+
case class EM[V2](apps: ExprMap[ExprMap[V2]]) extends EMImpl[V2, EM]:
8+
def collect[W](pf: PartialFunction[V2, W]): Unit =
9+
val apps1 = apps.collect(_.collect(pf))
10+
11+
case class ExprMap[V](var em: EM[V] = null) extends EMImpl[V, ExprMap]:
12+
def collect[W](pf: PartialFunction[V, W]): ExprMap[W] = ??? // was: StackOverflow in isCheckable

0 commit comments

Comments
 (0)