aboutsummaryrefslogtreecommitdiff
path: root/tests/pos/gadts2.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-08-22 16:16:06 +0200
committerMartin Odersky <odersky@gmail.com>2016-08-26 11:13:16 +0200
commit8f5bd779903d5c9f29bc3750391ffacbf3cf869e (patch)
treebb5cea499f596ca419de557fc1b0c0e9639745f7 /tests/pos/gadts2.scala
parent23d1bfb4111d8aff513659f2b3e3dd695b9b6e03 (diff)
downloaddotty-8f5bd779903d5c9f29bc3750391ffacbf3cf869e.tar.gz
dotty-8f5bd779903d5c9f29bc3750391ffacbf3cf869e.tar.bz2
dotty-8f5bd779903d5c9f29bc3750391ffacbf3cf869e.zip
GADT test
This one failed in getters before because a (previously unchecked) assignment was turned into a checked application. Now it passes.
Diffstat (limited to 'tests/pos/gadts2.scala')
-rw-r--r--tests/pos/gadts2.scala25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/pos/gadts2.scala b/tests/pos/gadts2.scala
new file mode 100644
index 000000000..71089c0f7
--- /dev/null
+++ b/tests/pos/gadts2.scala
@@ -0,0 +1,25 @@
+object Test {
+
+ abstract class Number
+ case class MyInt(n: Int) extends Number
+ case class MyDouble(d: Double) extends Number
+
+ trait Term[a]
+ case class Cell[a](var x: a) extends Term[a]
+ final case class NumTerm(val n: Number) extends Term[Number]
+
+ def f[A](t: Term[A], c: Cell[A]): Unit = {
+ t match {
+ case NumTerm(n) => c.x = MyDouble(1.0) // problem is: this assignment is not type correct, since gadt variable is forgotten
+ }
+ }
+
+ val x: Term[Number] = NumTerm(MyInt(5))
+
+ def main(args: Array[String]): Unit = {
+ val cell = Cell[Number](MyInt(6))
+ Console.println(cell)
+ f[Number](new NumTerm(MyInt(5)), cell)
+ Console.println(cell)
+ }
+}