From 050c9af51432e3a752715af78b0de577d5af7f87 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 19 Feb 2016 16:33:43 +0100 Subject: Special case for pattern matching tagged abstract types. Add special case when pattern matching against an abstract type that comes with a class tag --- tests/run/i1099.scala | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/run/i1099.scala (limited to 'tests/run/i1099.scala') diff --git a/tests/run/i1099.scala b/tests/run/i1099.scala new file mode 100644 index 000000000..15a428cc3 --- /dev/null +++ b/tests/run/i1099.scala @@ -0,0 +1,25 @@ +import scala.reflect.ClassTag +object Test { + def foo[T: ClassTag](x: Any) = + x match { + case t: T => true + case _ => false + } + // This is what `foo` expands to + def foo2[T](x: Any)(implicit ev: ClassTag[T]) = + x match { + case t @ ev(_) => true + case _ => false + } + def main(args: Array[String]): Unit = { + assert(foo[String]("a")) + assert(!foo[String](new Integer(1))) + assert(foo[Int](1)) + assert(!foo[Int](true)) + + assert(foo2[String]("a")) + assert(!foo2[String](new Integer(1))) + assert(foo2[Int](1)) + assert(!foo2[Int](true)) + } +} -- cgit v1.2.3