Skip to content

Commit 01fac53

Browse files
author
Aleksander Boruch-Gruszecki
committed
Add neg GADT test
1 parent 2433648 commit 01fac53

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

compiler/test/dotty/tools/dotc/GadtTests.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class GadtTests extends ParallelTesting {
2424
implicit val testGroup: TestGroup = TestGroup("compileGadtTests")
2525
compileFilesInDir("tests/gadt", defaultOptions).checkCompile()
2626
}
27+
28+
@Test def compileGadtNeg: Unit = {
29+
implicit val testGroup: TestGroup = TestGroup("compileGadtNeg")
30+
compileFilesInDir("tests/gadt-neg", defaultOptions).checkExpectedErrors()
31+
}
2732
}
2833

2934
object GadtTests {

tests/gadt-neg/banal-nested.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object banal {
2+
sealed trait T[A]
3+
final case class StrLit(v: String) extends T[String]
4+
final case class IntLit(v: Int) extends T[Int]
5+
6+
def eval[A](t: T[A]): A = t match {
7+
case _: T[a] => t match {
8+
case StrLit(v) => v
9+
case IntLit(_) => "" // error
10+
}
11+
}
12+
}

tests/gadt-neg/banal.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
object banal {
2+
final case class Box[A](a: A)
3+
4+
sealed trait T[A]
5+
final case class StrLit(v: String) extends T[String]
6+
final case class IntLit(v: Int) extends T[Int]
7+
8+
def evul[A](t: T[A]): A = t match {
9+
case StrLit(v) => (v: Any) // error
10+
case IntLit(v) => (??? : Nothing)
11+
}
12+
13+
def noeval[A](t: T[A]): Box[A] = t match {
14+
case StrLit(v) => Box[Any](v) // error
15+
case IntLit(v) => Box[Nothing](???) // error
16+
}
17+
}

tests/gadt-neg/i4075.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object i4075 {
2+
case class One[T](fst: T)
3+
def bad[T](e: One[T]) = e match {
4+
case foo: One[a] =>
5+
val nok: Nothing = foo.fst // error
6+
???
7+
}
8+
}

0 commit comments

Comments
 (0)