diff options
author | Nicolas Stucki <nicolas.stucki@gmail.com> | 2016-06-10 11:14:17 +0200 |
---|---|---|
committer | Nicolas Stucki <nicolas.stucki@gmail.com> | 2016-06-28 11:08:53 +0200 |
commit | b0ebe6ad30ce2584aa221b3ed8d10042bd9e97ac (patch) | |
tree | f7072a30b533821762dc0a18e5a5ba3e76e4ead5 /tests/neg | |
parent | cc87bd3b452e76ae974504c4f4e6beba996be3e8 (diff) | |
download | dotty-b0ebe6ad30ce2584aa221b3ed8d10042bd9e97ac.tar.gz dotty-b0ebe6ad30ce2584aa221b3ed8d10042bd9e97ac.tar.bz2 dotty-b0ebe6ad30ce2584aa221b3ed8d10042bd9e97ac.zip |
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.
Diffstat (limited to 'tests/neg')
-rw-r--r-- | tests/neg/tryPatternMatchError.scala | 35 |
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 => + } + } +} |