aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDmitry Petrashko <dark@d-d.me>2016-03-02 10:16:05 +0100
committerDmitry Petrashko <dark@d-d.me>2016-03-02 10:16:05 +0100
commitae624660d3cc31e9956d7e537c7a5c7925afda68 (patch)
tree12e28b3db9125c3afbb03c6331326f6fab29ae13 /tests
parent0ae3ef2010b90bf06d76a768b0f0c5aa56c1180a (diff)
parent1d2fe4823bc4c8a69351d49229556ac3a1532778 (diff)
downloaddotty-ae624660d3cc31e9956d7e537c7a5c7925afda68.tar.gz
dotty-ae624660d3cc31e9956d7e537c7a5c7925afda68.tar.bz2
dotty-ae624660d3cc31e9956d7e537c7a5c7925afda68.zip
Merge pull request #1111 from dotty-staging/fix-#1099
Special case pattern matching against abstract types with class tags
Diffstat (limited to 'tests')
-rw-r--r--tests/neg/arrayclone-new.scala38
-rw-r--r--tests/run/i1099.scala25
2 files changed, 25 insertions, 38 deletions
diff --git a/tests/neg/arrayclone-new.scala b/tests/neg/arrayclone-new.scala
deleted file mode 100644
index 0e42545f8..000000000
--- a/tests/neg/arrayclone-new.scala
+++ /dev/null
@@ -1,38 +0,0 @@
-// Run with -explaintypes to see information about shadowing failures
-import scala.reflect.{ClassTag, classTag}
-
-object Test extends dotty.runtime.LegacyApp{
- ObjectArrayClone;
- PolymorphicArrayClone;
-}
-
-object ObjectArrayClone{
- val it : Array[String] = Array("1", "0"); // error
- val cloned = it.clone();
- assert(cloned.sameElements(it));
- cloned(0) = "0";
- assert(it(0) == "1")
-}
-
-object PolymorphicArrayClone{
- def testIt[T](it : Array[T], one : T, zero : T) = {
- val cloned = it.clone();
- assert(cloned.sameElements(it));
- cloned(0) = zero;
- assert(it(0) == one)
- }
-
- testIt(Array("one", "two"), "one", "two"); // error
-
- class Mangler[T: ClassTag](ts : T*){
- // this will always be a BoxedAnyArray even after we've unboxed its contents.
- val it = ts.toArray[T];
- }
-
- val mangled = new Mangler[Int](0, 1);
-
- val y : Array[Int] = mangled.it; // make sure it's unboxed
-
- testIt(mangled.it, 0, 1);
-}
-
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))
+ }
+}