From 62162da42cd3b737ce196c6108dbe51ffdce37aa Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Mon, 6 May 2019 10:00:49 +0200 Subject: [PATCH 1/2] Add tests for tree.pos.sourceCode --- .../reflect-sourceCode/Macro_1.scala | 12 ++++++++++++ .../reflect-sourceCode/Test_2.scala | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/run-with-compiler/reflect-sourceCode/Macro_1.scala create mode 100644 tests/run-with-compiler/reflect-sourceCode/Test_2.scala diff --git a/tests/run-with-compiler/reflect-sourceCode/Macro_1.scala b/tests/run-with-compiler/reflect-sourceCode/Macro_1.scala new file mode 100644 index 000000000000..2ba5c55f19c1 --- /dev/null +++ b/tests/run-with-compiler/reflect-sourceCode/Macro_1.scala @@ -0,0 +1,12 @@ +import scala.quoted._ +import scala.tasty._ + +object api { + inline def (x: => T) reflect[T] : String = + ${ reflImpl('x) } + + private def reflImpl[T](x: Expr[T])(implicit refl: Reflection): Expr[String] = { + import refl._ + x.unseal.pos.sourceCode.toExpr + } +} diff --git a/tests/run-with-compiler/reflect-sourceCode/Test_2.scala b/tests/run-with-compiler/reflect-sourceCode/Test_2.scala new file mode 100644 index 000000000000..a932a8bff657 --- /dev/null +++ b/tests/run-with-compiler/reflect-sourceCode/Test_2.scala @@ -0,0 +1,15 @@ +import api._ + +object Test { + def f(implicit x: Int): Int = x * x + def main(args: Array[String]): Unit = { + implicit val x: Int = 10 + assert(args(0).reflect == "args(0)") + assert(args( 0 ).reflect == "args( 0 )") + assert(args( 0 /* ignore */).reflect == "args( 0 /* ignore */)") + assert(f.reflect == "f") + assert((f).reflect == "f") + assert( { f }.reflect == "f") + assert( { f; f }.reflect == "f") + } +} From a1a2b10db8f7641f48fd23d2c7c0fcd3b79f5acd Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Tue, 9 Jul 2019 10:50:29 +0200 Subject: [PATCH 2/2] Update test: the problem is already fixed in master --- tests/run-with-compiler/reflect-sourceCode/Test_2.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/run-with-compiler/reflect-sourceCode/Test_2.scala b/tests/run-with-compiler/reflect-sourceCode/Test_2.scala index a932a8bff657..a1a6d6562473 100644 --- a/tests/run-with-compiler/reflect-sourceCode/Test_2.scala +++ b/tests/run-with-compiler/reflect-sourceCode/Test_2.scala @@ -9,7 +9,7 @@ object Test { assert(args( 0 /* ignore */).reflect == "args( 0 /* ignore */)") assert(f.reflect == "f") assert((f).reflect == "f") - assert( { f }.reflect == "f") - assert( { f; f }.reflect == "f") + assert( { f }.reflect == "{ f }") + assert( { f; f }.reflect == "{ f; f }") } }