summaryrefslogtreecommitdiff
path: root/test/files/neg/patmat-type-check.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-18 05:40:27 +0000
committerPaul Phillips <paulp@improving.org>2010-02-18 05:40:27 +0000
commit23e5428008fc88377e59a1a5c20d5476c586d62e (patch)
tree45a0eb248c9d7c11674c6d0484c009518197d0d4 /test/files/neg/patmat-type-check.scala
parentcf2f9d7fbe4311b2373957b4bc78520984f4eafc (diff)
downloadscala-23e5428008fc88377e59a1a5c20d5476c586d62e.tar.gz
scala-23e5428008fc88377e59a1a5c20d5476c586d62e.tar.bz2
scala-23e5428008fc88377e59a1a5c20d5476c586d62e.zip
Tighter pattern matching hits the street.
is final and does not conform to the pattern, it will no longer compile. See all the exciting things you can no longer do: "bob".reverse match { case Seq('b', 'o', 'b') => true } // denied! "bob".toArray match { case Seq('b', 'o', 'b') => true } // rejected! final class Dunk def f3(x: Dunk) = x match { case Seq('b', 'o', 'b') => true } // uh-uh! And so forth. Review by odersky.
Diffstat (limited to 'test/files/neg/patmat-type-check.scala')
-rw-r--r--test/files/neg/patmat-type-check.scala28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/files/neg/patmat-type-check.scala b/test/files/neg/patmat-type-check.scala
new file mode 100644
index 0000000000..c6c689b256
--- /dev/null
+++ b/test/files/neg/patmat-type-check.scala
@@ -0,0 +1,28 @@
+object Test
+{
+ def s1 = "bob".toList match { case Seq('b', 'o', 'b') => true } // list ok
+
+ // not final, allowed
+ class Bop
+ def s2(x: Bop) = x match { case Seq('b', 'o', 'b') => true }
+
+ // covariance, allowed
+ final class Bop4[+T]
+ def s3[T](x: Bop4[T]) = x match { case Seq('b', 'o', 'b') => true }
+
+ // contravariance, allowed
+ final class Bop5[T, U, -V]
+ def s4[T1, T2](x: Bop5[_, T1, T2]) = x match { case Seq('b', 'o', 'b') => true }
+
+ // String and Array are final/invariant, disallowed
+ def f1 = "bob".reverse match { case Seq('b', 'o', 'b') => true } // fail
+ def f2 = "bob".toArray match { case Seq('b', 'o', 'b') => true } // fail
+
+ // final, no type parameters, should be disallowed
+ final class Bop2
+ def f3(x: Bop2) = x match { case Seq('b', 'o', 'b') => true } // fail
+
+ // final, invariant type parameter, should be disallowed
+ final class Bop3[T]
+ def f4[T](x: Bop3[T]) = x match { case Seq('b', 'o', 'b') => true } // fail
+}