diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2014-09-11 14:56:13 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-09-11 14:56:13 +0200 |
commit | 3b35177e7620da91e8c77ed5d16ef168b64e58b8 (patch) | |
tree | fef119e2680e3378aa202207e2b7ed482a5258db /test/files/pos/t8719 | |
parent | 7c8eaef41cacaa34cd691fb81e58d2d80428c661 (diff) | |
download | scala-3b35177e7620da91e8c77ed5d16ef168b64e58b8.tar.gz scala-3b35177e7620da91e8c77ed5d16ef168b64e58b8.tar.bz2 scala-3b35177e7620da91e8c77ed5d16ef168b64e58b8.zip |
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.
Diffstat (limited to 'test/files/pos/t8719')
-rw-r--r-- | test/files/pos/t8719/Macros_1.scala | 21 | ||||
-rw-r--r-- | test/files/pos/t8719/Test_2.scala | 10 |
2 files changed, 31 insertions, 0 deletions
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 |