From 803d869a2e179f81e235261ef008c0ef8fb11e8c Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Sun, 10 Mar 2019 13:09:38 +0100 Subject: [PATCH] Fix #5629: Add regression test --- tests/run/i5629/Macro_1.scala | 20 ++++++++++++++++++++ tests/run/i5629/Test_2.scala | 10 ++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/run/i5629/Macro_1.scala create mode 100644 tests/run/i5629/Test_2.scala diff --git a/tests/run/i5629/Macro_1.scala b/tests/run/i5629/Macro_1.scala new file mode 100644 index 000000000000..51dccd65a4ad --- /dev/null +++ b/tests/run/i5629/Macro_1.scala @@ -0,0 +1,20 @@ +import scala.quoted._ +import scala.tasty._ + +object Macros { + + inline def assert(condition: => Boolean): Unit = ${ assertImpl('{condition}, '{""}) } + + def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = { + import refl._ + val b = cond.unseal.underlyingArgument.seal[Boolean] + '{ scala.Predef.assert($b) } + } + + inline def thisLineNumber = ${ thisLineNumberImpl } + + def thisLineNumberImpl(implicit refl: Reflection): Expr[Int] = { + import refl._ + refl.rootPosition.startLine.toExpr + } +} diff --git a/tests/run/i5629/Test_2.scala b/tests/run/i5629/Test_2.scala new file mode 100644 index 000000000000..329f3be6aee7 --- /dev/null +++ b/tests/run/i5629/Test_2.scala @@ -0,0 +1,10 @@ +object Test { + import Macros._ + + def main(args: Array[String]): Unit = { + val startLine = thisLineNumber + assert(thisLineNumber == startLine + 1) + assert(thisLineNumber == startLine + 2) + scala.Predef.assert(thisLineNumber == startLine + 3) + } +}