diff options
Diffstat (limited to 'test/files/neg')
-rw-r--r-- | test/files/neg/bug1878.check | 7 | ||||
-rw-r--r-- | test/files/neg/patmat-type-check.check | 21 | ||||
-rw-r--r-- | test/files/neg/patmat-type-check.scala | 28 |
3 files changed, 55 insertions, 1 deletions
diff --git a/test/files/neg/bug1878.check b/test/files/neg/bug1878.check index 5484d675af..f760781fa0 100644 --- a/test/files/neg/bug1878.check +++ b/test/files/neg/bug1878.check @@ -1,10 +1,15 @@ bug1878.scala:3: error: _* may only come last val err1 = "" match { case Seq(f @ _*, ',') => f } ^ +bug1878.scala:3: error: scrutinee is incompatible with pattern type; + found : Seq[A] + required: java.lang.String + val err1 = "" match { case Seq(f @ _*, ',') => f } + ^ bug1878.scala:9: error: _* may only come last val List(List(_*, arg2), _) = List(List(1,2,3), List(4,5,6)) ^ bug1878.scala:13: error: _* may only come last case <p> { _* } </p> => ^ -three errors found +four errors found diff --git a/test/files/neg/patmat-type-check.check b/test/files/neg/patmat-type-check.check new file mode 100644 index 0000000000..ab638b616d --- /dev/null +++ b/test/files/neg/patmat-type-check.check @@ -0,0 +1,21 @@ +patmat-type-check.scala:18: error: scrutinee is incompatible with pattern type; + found : Seq[A] + required: java.lang.String + def f1 = "bob".reverse match { case Seq('b', 'o', 'b') => true } // fail + ^ +patmat-type-check.scala:19: error: scrutinee is incompatible with pattern type; + found : Seq[A] + required: Array[Char] + def f2 = "bob".toArray match { case Seq('b', 'o', 'b') => true } // fail + ^ +patmat-type-check.scala:23: error: scrutinee is incompatible with pattern type; + found : Seq[A] + required: Test.Bop2 + def f3(x: Bop2) = x match { case Seq('b', 'o', 'b') => true } // fail + ^ +patmat-type-check.scala:27: error: scrutinee is incompatible with pattern type; + found : Seq[A] + required: Test.Bop3[T] + def f4[T](x: Bop3[T]) = x match { case Seq('b', 'o', 'b') => true } // fail + ^ +four errors found 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 +} |