File tree 4 files changed +42
-0
lines changed
compiler/test/dotty/tools/dotc
4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,11 @@ class GadtTests extends ParallelTesting {
24
24
implicit val testGroup : TestGroup = TestGroup (" compileGadtTests" )
25
25
compileFilesInDir(" tests/gadt" , defaultOptions).checkCompile()
26
26
}
27
+
28
+ @ Test def compileGadtNeg : Unit = {
29
+ implicit val testGroup : TestGroup = TestGroup (" compileGadtNeg" )
30
+ compileFilesInDir(" tests/gadt-neg" , defaultOptions).checkExpectedErrors()
31
+ }
27
32
}
28
33
29
34
object GadtTests {
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments