Skip to content

Commit

Permalink
Backport "Short-circuit isCheckable with classSymbol" to LTS (#20942)
Browse files Browse the repository at this point in the history
Backports #19634 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jul 2, 2024
2 parents 56079bf + dfc78fa commit dc70b77
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 dc70b77

Please sign in to comment.