From 3b35177e7620da91e8c77ed5d16ef168b64e58b8 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Thu, 11 Sep 2014 14:56:13 +0200 Subject: This ensures that typechecking custom unapplications in silent mode doesn't leak uncatchable errors. Interestingly enough, the problem only manifested itself for custom unapply methods, not for synthetic ones generated for case classes. --- test/files/pos/t8719.check | 0 test/files/pos/t8719/Macros_1.scala | 21 +++++++++++++++++++++ test/files/pos/t8719/Test_2.scala | 10 ++++++++++ 3 files changed, 31 insertions(+) create mode 100644 test/files/pos/t8719.check create mode 100644 test/files/pos/t8719/Macros_1.scala create mode 100644 test/files/pos/t8719/Test_2.scala (limited to 'test') diff --git a/test/files/pos/t8719.check b/test/files/pos/t8719.check new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/files/pos/t8719/Macros_1.scala b/test/files/pos/t8719/Macros_1.scala new file mode 100644 index 0000000000..152c92f254 --- /dev/null +++ b/test/files/pos/t8719/Macros_1.scala @@ -0,0 +1,21 @@ +import scala.language.experimental.macros +import scala.reflect.macros.TypecheckException +import scala.reflect.macros.whitebox.Context + +object Macros { + def typecheck_impl(c: Context)(code: c.Expr[String]): c.Expr[Option[String]] = { + import c.universe._ + + val Expr(Literal(Constant(codeStr: String))) = code + + try { + c.typecheck(c.parse(codeStr)) + c.Expr(q"None: Option[String]") + } catch { + case e: TypecheckException => + c.Expr(q"Some(${ e.toString }): Option[String]") + } + } + + def typecheck(code: String): Option[String] = macro typecheck_impl +} \ No newline at end of file diff --git a/test/files/pos/t8719/Test_2.scala b/test/files/pos/t8719/Test_2.scala new file mode 100644 index 0000000000..997eb2f236 --- /dev/null +++ b/test/files/pos/t8719/Test_2.scala @@ -0,0 +1,10 @@ +case class Foo(i: Int, c: Char) + +object Bar { + def unapply(foo: Foo): Option[(Int, Char)] = Some((foo.i, foo.c)) +} + +object Test extends App { + println(Macros.typecheck("val Foo(x, y, z) = Foo(1, 'a')")) + println(Macros.typecheck("val Bar(x, y, z) = Foo(1, 'a')")) +} \ No newline at end of file -- cgit v1.2.3