diff options
author | Paul Phillips <paulp@improving.org> | 2010-10-04 05:28:27 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-10-04 05:28:27 +0000 |
commit | a7fd7d6dc257e396cf2cf22a9e0a60c3ce44a992 (patch) | |
tree | 24dab3548d8cef970a748d149ebd566cce808e64 /test/files/neg/patmat-type-check.scala | |
parent | afea859ef64122f71525405625d0006150d87fb0 (diff) | |
download | scala-a7fd7d6dc257e396cf2cf22a9e0a60c3ce44a992.tar.gz scala-a7fd7d6dc257e396cf2cf22a9e0a60c3ce44a992.tar.bz2 scala-a7fd7d6dc257e396cf2cf22a9e0a60c3ce44a992.zip |
Pattern matching on Array types, working for re...
Pattern matching on Array types, working for reals.
def f[T](a: Array[T]) = a match {
case x: Array[Int] => x(0)
case x: Array[Double] => 2
// etc.
}
I'd also like to thank "instantiateTypeVar" for displacing the
mechanical spiders and giant squid beings which used to fill my
nightmares. Now that I know true horror, I welcome the squid.
Closes #2755, review by odersky.
Diffstat (limited to 'test/files/neg/patmat-type-check.scala')
-rw-r--r-- | test/files/neg/patmat-type-check.scala | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/test/files/neg/patmat-type-check.scala b/test/files/neg/patmat-type-check.scala index c6c689b256..26d0409fa0 100644 --- a/test/files/neg/patmat-type-check.scala +++ b/test/files/neg/patmat-type-check.scala @@ -14,6 +14,10 @@ object Test final class Bop5[T, U, -V] def s4[T1, T2](x: Bop5[_, T1, T2]) = x match { case Seq('b', 'o', 'b') => true } + // free type parameter, allowed + final class Bop3[T] + def f4[T](x: Bop3[T]) = 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 @@ -23,6 +27,5 @@ object Test 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 + def f4[T](x: Bop3[Char]) = x match { case Seq('b', 'o', 'b') => true } // fail } |