Skip to content

Commit

Permalink
Merge pull request #9163 from dwijnand/exhaust-tuple-unsealed-false-p…
Browse files Browse the repository at this point in the history
…ositive

Fix exhaustivity uncheckableType's logic for tuples
  • Loading branch information
lrytz committed Sep 7, 2020
2 parents d3fb332 + e5bda18 commit 24f3c54
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
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

0 comments on commit 24f3c54

Please sign in to comment.