From 15189d14953335f7a3a8310861d045d21ab22d48 Mon Sep 17 00:00:00 2001 From: Ben Hutchison Date: Thu, 19 May 2016 17:01:45 +1000 Subject: Test case for SI-5183, tagged primitives in case classes (#5144) Test for SI-7088, arrays containing tagged primitives --- test/files/pos/t5183.scala | 34 ++++++++++++++++++++++++++++++++++ test/files/pos/t7088.scala | 8 ++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/files/pos/t5183.scala create mode 100644 test/files/pos/t7088.scala 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) +} -- cgit v1.2.3