From b0ebe6ad30ce2584aa221b3ed8d10042bd9e97ac Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 10 Jun 2016 11:14:17 +0200 Subject: Fix #856: Handle try/catch cases as catch cases if possible. Previously they were all lifted into a match with the came cases. Now the first cases are handled directly by by the catch. If one of the cases can not be handled the old scheme is applied to to it and all subsequent cases. --- tests/neg/tryPatternMatchError.scala | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/neg/tryPatternMatchError.scala (limited to 'tests/neg/tryPatternMatchError.scala') 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 => + } + } +} -- cgit v1.2.3