Skip to content

add more gadt exhaustivity check tests #3999

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 5 commits into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions tests/patmat/gadt2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
sealed trait Nat[+T]
case class Zero() extends Nat[Nothing]
case class Succ[T]() extends Nat[T]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not intended to be a correct representation of Peano numerals, right? Not only for the +T but also because T in Succ is completely unconstrained...


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

object Test {
def foo[N <: Nat[_], A, B](v1: Vect[N, A], v2: Vect[N, B]) = (v1, v2) match {
case (VN(), VN()) => 1
case (VC(x, xs), VC(y, ys)) => 2
}
}
1 change: 1 addition & 0 deletions tests/patmat/gadt4.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12: Pattern Match Exhaustivity: (VC(_, _), VN()), (VN(), VC(_, _))
2 changes: 2 additions & 0 deletions tests/patmat/gadt2.scala.ignore → tests/patmat/gadt4.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ sealed trait Nat[+T]
case class Zero() extends Nat[Nothing]
case class Succ[T]() extends Nat[T]

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