diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-09-18 09:25:38 +0200 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-09-18 09:25:38 +0200 |
commit | 2c23a5e70288c4b00c8c06c6ae5b6e65eede6ac0 (patch) | |
tree | c4cee58684aee2831dc8b14b73207b83207d8ecf /test/files | |
parent | 190c6726158f3f7e1ac5d26782437c184cee5872 (diff) | |
parent | 3b35177e7620da91e8c77ed5d16ef168b64e58b8 (diff) | |
download | scala-2c23a5e70288c4b00c8c06c6ae5b6e65eede6ac0.tar.gz scala-2c23a5e70288c4b00c8c06c6ae5b6e65eede6ac0.tar.bz2 scala-2c23a5e70288c4b00c8c06c6ae5b6e65eede6ac0.zip |
Merge pull request #3974 from xeno-by/topic/buffer-pattern-expander-errors
This ensures that typechecking custom unapplications in silent mode
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/pos/t8719.check | 0 | ||||
-rw-r--r-- | test/files/pos/t8719/Macros_1.scala | 21 | ||||
-rw-r--r-- | test/files/pos/t8719/Test_2.scala | 10 |
3 files changed, 31 insertions, 0 deletions
diff --git a/test/files/pos/t8719.check b/test/files/pos/t8719.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/pos/t8719.check 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 |