Skip to content
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

Short-circuit isCheckable with classSymbol #19634

Merged
merged 1 commit into from
Feb 27, 2024
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
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 @@ -773,7 +773,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 @@ -789,7 +789,7 @@ object SpaceEngine {
tpw.isRef(defn.BooleanClass) ||
classSym.isAllOf(JavaEnum) ||
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
Loading