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

Fix exhaustivity uncheckableType's logic for tuples #9163

Merged
merged 1 commit into from Sep 7, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -213,9 +213,10 @@ trait TreeAndTypeAnalysis extends Debugging {
// a type is "uncheckable" (for exhaustivity) if we don't statically know its subtypes (i.e., it's unsealed)
// we consider tuple types with at least one component of a checkable type as a checkable type
def uncheckableType(tp: Type): Boolean = {
val checkable = (
(isTupleType(tp) && tupleComponents(tp).exists(tp => !uncheckableType(tp)))
|| enumerateSubtypes(tp, grouped = false).nonEmpty)
val checkable = {
if (isTupleType(tp)) tupleComponents(tp).exists(tp => !uncheckableType(tp))
else enumerateSubtypes(tp, grouped = false).nonEmpty
}
// if (!checkable) debug.patmat("deemed uncheckable: "+ tp)
!checkable
}
Expand Down
1 change: 1 addition & 0 deletions test/files/pos/t10373.flags
@@ -0,0 +1 @@
-Xfatal-warnings
15 changes: 15 additions & 0 deletions test/files/pos/t10373.scala
@@ -0,0 +1,15 @@
abstract class Foo {
def bar(): Unit = this match {
case Foo_1() => //do something
case Foo_2() => //do something
// Works fine
}

def baz(that: Foo): Unit = (this, that) match {
case (Foo_1(), _) => //do something
case (Foo_2(), _) => //do something
// match may not be exhaustive
}
}
case class Foo_1() extends Foo
case class Foo_2() extends Foo