summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hutchison <brhutchison@gmail.com>2016-05-19 17:01:45 +1000
committerLukas Rytz <lukas.rytz@typesafe.com>2016-05-19 09:01:45 +0200
commit15189d14953335f7a3a8310861d045d21ab22d48 (patch)
treee02b64894cda16361205779c95039d79fa2d6697
parent960e4d76a382ff009c66346289db10b2ee598aa5 (diff)
downloadscala-15189d14953335f7a3a8310861d045d21ab22d48.tar.gz
scala-15189d14953335f7a3a8310861d045d21ab22d48.tar.bz2
scala-15189d14953335f7a3a8310861d045d21ab22d48.zip
Test case for SI-5183, tagged primitives in case classes (#5144)
Test for SI-7088, arrays containing tagged primitives
-rw-r--r--test/files/pos/t5183.scala34
-rw-r--r--test/files/pos/t7088.scala8
2 files changed, 42 insertions, 0 deletions
diff --git a/test/files/pos/t5183.scala b/test/files/pos/t5183.scala
new file mode 100644
index 0000000000..783b8c28dc
--- /dev/null
+++ b/test/files/pos/t5183.scala
@@ -0,0 +1,34 @@
+trait Day
+
+object Test {
+ def foo(t: Int with Day) = t == t
+}
+
+class DayOps(val i: Int with Day) extends AnyVal
+
+case class Test1(d: Int with Day)
+case class Test2(d1: Int with Day, d2: Int with Day)
+
+class User
+class Checkin
+object Example {
+
+ type Tagged[U] = { type Tag = U }
+ type @@[T, U] = T with Tagged[U] // Thanks to @retronym for suggesting this type alias
+
+ class Tagger[U] {
+ def apply[T](t : T) : T @@ U = t.asInstanceOf[T @@ U]
+ }
+ def tag[U] = new Tagger[U]
+
+ // Manual specialization needed here ... specializing apply above doesn't help
+ def tag[U](i : Int) : Int @@ U = i.asInstanceOf[Int @@ U]
+ def tag[U](l : Long) : Long @@ U = l.asInstanceOf[Long @@ U]
+ def tag[U](d : Double) : Double @@ U = d.asInstanceOf[Double @@ U]
+
+ def fetch[A](id: Int @@ A): A = null.asInstanceOf[A]
+
+ def tag[U](arr: Array[Int]):Array[Int @@ U] = arr.asInstanceOf[Array[Int @@ U]]
+
+ tag[User](Array(3, 4, 5)).map(_.toString)
+} \ No newline at end of file
diff --git a/test/files/pos/t7088.scala b/test/files/pos/t7088.scala
new file mode 100644
index 0000000000..de9d1b7040
--- /dev/null
+++ b/test/files/pos/t7088.scala
@@ -0,0 +1,8 @@
+object Example extends App {
+ type Tag[X] = {type Tag = X}
+ type TaggedArray[T] = Array[T] with Tag[Any]
+
+ def method[T: reflect.ClassTag](a: TaggedArray[T], value: T) {a.update(0, value)}
+
+ method(Array(1, 2).asInstanceOf[TaggedArray[Int]], 1)
+}