Skip to content

Add exhaustivity check tests #6894

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

Merged
merged 2 commits into from
Jul 19, 2019
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
17 changes: 17 additions & 0 deletions tests/patmat/t11283.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
sealed trait Color
case object Red extends Color
case object Blue extends Color
case object Green extends Color

class Test {

val R: Red.type = Red
val B: Blue.type = Blue
val G: Green.type = Green

def go(c: Color): Int = c match {
case R => 0
case G => 1
case B => 2
}
}
13 changes: 13 additions & 0 deletions tests/patmat/t11457.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sealed abstract class Foo(val a: String)

object Foo {
def unapply(foo: Foo): Some[String] =
Some(foo.a)
}

class Issue11457 {
val root: PartialFunction[Foo, Boolean] = {
case Foo("a") => true
case Foo("b") => false
}
}
5 changes: 5 additions & 0 deletions tests/patmat/t11603.scala.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class C {
def m(x: true) = x match {
case true => println("the one true path")
}
}
1 change: 1 addition & 0 deletions tests/patmat/t11620.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
36: Pattern Match Exhaustivity: B(A2(_, _))
38 changes: 38 additions & 0 deletions tests/patmat/t11620.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
sealed trait A[+T]
case class A1[+T](t : T ) extends A[T]
case class A2[+T](t1: T, t2: T) extends A[T]

sealed trait B[+T] {
type AA[+U] <: A[U]
def a: AA[T]
}
object B {
type Aux[+_A[+_], +T] = B[T] { type AA[+U] <: _A[U] }
object Aux {
def unapply[_A[+U] <: A[U], T](b: Aux[_A, T]): Some[_A[T]] = Some(b.a)
}

def apply[_A[+U] <: A[U], T](_a: _A[T]): Aux[_A, T] =
new B[T] { type AA[+U] = _A[U] ; val a: _A[T] = _a }

def unapply[T](b: B[T]): Some[b.AA[T]] = Some(b.a)
}

def foo[T](b: B[T]) = b match {
case B(A1(t)) ⇒ t
case B(A2(t, _)) ⇒ t
}

def foo2[_A[+U] <: A[U], T](b: B.Aux[_A, T]) = b match {
case B.Aux(a @ A1(_ )) ⇒ a.t
case B.Aux(a @ A2(_, _)) ⇒ a.t1 // 👎 (false-positive): unreachable code
}

def foo3[_A[+U] <: A[U], T](b: B.Aux[_A, T]) = b match {
case B.Aux(a: A1[T]) ⇒ a.t
case B.Aux(a: A2[T]) ⇒ a.t1 // 👎 (false-positive): unreachable code
}

def foo4[T](b: B[T]) = b match {
case B(A1(t)) ⇒ t // 👎 (false-negative): incomplete match
}
2 changes: 2 additions & 0 deletions tests/patmat/t9809.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
3: Pattern Match Exhaustivity: (_, _)
7: Pattern Match Exhaustivity: (_, _)
9 changes: 9 additions & 0 deletions tests/patmat/t9809.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
object Example {
val op1: (Any, Any) => Unit = {
case (_, b: Int) =>
}

val op2: (Unit, Any) => Unit = {
case (_, b: Int) =>
}
}