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..a1a6d6562473 --- /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; f }") + } +}