Skip to content

Commit e1a068a

Browse files
committed
add gadt exhaustivity check test
1 parent 3365ed3 commit e1a068a

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

tests/patmat/gadt2.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sealed trait Nat[+T]
2+
case class Zero() extends Nat[Nothing]
3+
case class Succ[T]() extends Nat[T]
4+
5+
// +N is incorrect, as in `foo` we can have `N = Zero | Succ[Zero]`,
6+
// then it's correct for exhaustivity check to produce two warnings.
7+
sealed trait Vect[N <: Nat[_], +T]
8+
case class VN[T]() extends Vect[Zero, T]
9+
case class VC[T, N <: Nat[_]](x: T, xs: Vect[N, T]) extends Vect[Succ[N], T]
10+
11+
object Test {
12+
def foo[N <: Nat[_], A, B](v1: Vect[N, A], v2: Vect[N, B]) = (v1, v2) match {
13+
case (VN(), VN()) => 1
14+
case (VC(x, xs), VC(y, ys)) => 2
15+
}
16+
}

tests/patmat/gadt4.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12: Pattern Match Exhaustivity: (VC(_, _), VN()), (VN(), VC(_, _))

tests/patmat/gadt2.scala.ignore renamed to tests/patmat/gadt4.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ sealed trait Nat[+T]
22
case class Zero() extends Nat[Nothing]
33
case class Succ[T]() extends Nat[T]
44

5+
// +N is incorrect, as in `foo` we can have `N = Zero | Succ[Zero]`,
6+
// then it's correct for exhaustivity check to produce two warnings.
57
sealed trait Vect[+N <: Nat[_], +T]
68
case class VN[T]() extends Vect[Zero, T]
79
case class VC[T, N <: Nat[_]](x: T, xs: Vect[N, T]) extends Vect[Succ[N], T]

0 commit comments

Comments
 (0)