From 006e2f2aadf5d15ff1b9b32f1b7e96960b778933 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Tue, 10 Dec 2013 00:45:48 +0100 Subject: SI-7912 Be defensive calling `toString` in `MatchError#getMessage` Otherwise, objects with exception-throwing `toString` lead to a cascading error far removed from the originally failed match. --- test/files/run/t7912.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/files/run/t7912.scala (limited to 'test/files') diff --git a/test/files/run/t7912.scala b/test/files/run/t7912.scala new file mode 100644 index 0000000000..3d603e0e97 --- /dev/null +++ b/test/files/run/t7912.scala @@ -0,0 +1,16 @@ +case object A { override def toString = ??? } + +object Test { + def foo: Int = (A: Any) match { + case 0 => 0 + } + def main(args: Array[String]): Unit = { + try { + foo + sys.error("no exception") + } catch { + case me: MatchError => assert(me.getMessage == "an instance of class A$", me.getMessage) + case ex: Throwable => sys.error("not a match error: " + ex.getClass) + } + } +} -- cgit v1.2.3