aboutsummaryrefslogtreecommitdiff
path: root/tests/neg
diff options
context:
space:
mode:
Diffstat (limited to 'tests/neg')
-rw-r--r--tests/neg/tryPatternMatchError.scala35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/neg/tryPatternMatchError.scala b/tests/neg/tryPatternMatchError.scala
new file mode 100644
index 000000000..fe12a6232
--- /dev/null
+++ b/tests/neg/tryPatternMatchError.scala
@@ -0,0 +1,35 @@
+import java.io.IOException
+import java.lang.NullPointerException
+import java.lang.IllegalArgumentException
+
+object IAE {
+ def unapply(e: Exception): Option[String] =
+ if (e.isInstanceOf[IllegalArgumentException]) Some(e.getMessage)
+ else None
+}
+
+object EX extends Exception
+
+trait ExceptionTrait extends Exception
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ var a: Int = 1
+ try {
+ throw new IllegalArgumentException()
+ } catch {
+ case e: IOException if e.getMessage == null =>
+ case e: NullPointerException =>
+ case e: IndexOutOfBoundsException =>
+ case _: NoSuchElementException =>
+ case _: ExceptionTrait =>
+ case _: NoSuchElementException if a <= 1 =>
+ case _: NullPointerException | _:IOException =>
+ case `a` => // This case should probably emmit an error
+ case e: Int => // error
+ case EX =>
+ case IAE(msg) =>
+ case e: IllegalArgumentException =>
+ }
+ }
+}