Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add neg GADT test
  • Loading branch information
Aleksander Boruch-Gruszecki committed Nov 22, 2018
commit df2bc0547a572b9747a71e08e44ef92a179efcd3
5 changes: 5 additions & 0 deletions compiler/test/dotty/tools/dotc/GadtTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class GadtTests extends ParallelTesting {
implicit val testGroup: TestGroup = TestGroup("compileGadtTests")
compileFilesInDir("tests/gadt", defaultOptions).checkCompile()
}

@Test def compileGadtNeg: Unit = {
implicit val testGroup: TestGroup = TestGroup("compileGadtNeg")
compileFilesInDir("tests/gadt-neg", defaultOptions).checkExpectedErrors()
}
}

object GadtTests {
Expand Down
12 changes: 12 additions & 0 deletions tests/gadt-neg/banal-nested.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
object banal {
sealed trait T[A]
final case class StrLit(v: String) extends T[String]
final case class IntLit(v: Int) extends T[Int]

def eval[A](t: T[A]): A = t match {
case _: T[a] => t match {
case StrLit(v) => v
case IntLit(_) => "" // error
}
}
}
17 changes: 17 additions & 0 deletions tests/gadt-neg/banal.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
object banal {
final case class Box[A](a: A)

sealed trait T[A]
final case class StrLit(v: String) extends T[String]
final case class IntLit(v: Int) extends T[Int]

def evul[A](t: T[A]): A = t match {
case StrLit(v) => (v: Any) // error
case IntLit(v) => (??? : Nothing)
}

def noeval[A](t: T[A]): Box[A] = t match {
case StrLit(v) => Box[Any](v) // error
case IntLit(v) => Box[Nothing](???) // error
}
}
8 changes: 8 additions & 0 deletions tests/gadt-neg/i4075.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object i4075 {
case class One[T](fst: T)
def bad[T](e: One[T]) = e match {
case foo: One[a] =>
val nok: Nothing = foo.fst // error
???
}
}