From ccf6c2ab3822729ff23eb917ee625f9e79804d53 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 17 Sep 2020 10:21:13 +0200 Subject: [PATCH] Fix #9801: Make sure the errors are reported --- .../dotty/tools/dotc/transform/Splicer.scala | 4 ++-- tests/neg-macros/i9801/Macro_1.scala | 20 +++++++++++++++++++ tests/neg-macros/i9801/Test_2.scala | 1 + tests/neg-macros/i9801b/Macro_1.scala | 14 +++++++++++++ tests/neg-macros/i9801b/Test_2.scala | 1 + 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 tests/neg-macros/i9801/Macro_1.scala create mode 100644 tests/neg-macros/i9801/Test_2.scala create mode 100644 tests/neg-macros/i9801b/Macro_1.scala create mode 100644 tests/neg-macros/i9801b/Test_2.scala diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index addc3edd6e07..8bece8e32b07 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -65,7 +65,7 @@ object Splicer { EmptyTree case ex: StopInterpretation => report.error(ex.msg, ex.pos) - EmptyTree + ref(defn.Predef_undefined).withType(ErrorType(ex.msg)) case NonFatal(ex) => val msg = s"""Failed to evaluate macro. @@ -73,7 +73,7 @@ object Splicer { | ${ex.getStackTrace.takeWhile(_.getClassName != "dotty.tools.dotc.transform.Splicer$").drop(1).mkString("\n ")} """.stripMargin report.error(msg, pos) - EmptyTree + ref(defn.Predef_undefined).withType(ErrorType(msg)) } } diff --git a/tests/neg-macros/i9801/Macro_1.scala b/tests/neg-macros/i9801/Macro_1.scala new file mode 100644 index 000000000000..5bf2106548f9 --- /dev/null +++ b/tests/neg-macros/i9801/Macro_1.scala @@ -0,0 +1,20 @@ +import scala.quoted._ + +def f() = () + +def triggerStackOverflow(n: Int): Expr[Double] = { + val r = triggerStackOverflow(n - 1) + f() + r +} + +inline def loop(inline prog: Double): Double = ${impl('prog)} + +def impl(prog: Expr[Double])(using QuoteContext) : Expr[Double] = + try { + triggerStackOverflow(0) + } catch { + case e => + qctx.tasty.error(e.getMessage, prog.unseal.pos) + '{ 42.0 } + } diff --git a/tests/neg-macros/i9801/Test_2.scala b/tests/neg-macros/i9801/Test_2.scala new file mode 100644 index 000000000000..7a79536738c3 --- /dev/null +++ b/tests/neg-macros/i9801/Test_2.scala @@ -0,0 +1 @@ +def test: Unit = loop(4) // error diff --git a/tests/neg-macros/i9801b/Macro_1.scala b/tests/neg-macros/i9801b/Macro_1.scala new file mode 100644 index 000000000000..87360ff06093 --- /dev/null +++ b/tests/neg-macros/i9801b/Macro_1.scala @@ -0,0 +1,14 @@ +import scala.quoted._ + +def f() = () + +def triggerStackOverflow(n: Int): Expr[Double] = { + val r = triggerStackOverflow(n - 1) + f() + r +} + +inline def loop(inline prog: Double): Double = ${impl('prog)} + +def impl(prog: Expr[Double])(using QuoteContext) : Expr[Double] = + triggerStackOverflow(0) diff --git a/tests/neg-macros/i9801b/Test_2.scala b/tests/neg-macros/i9801b/Test_2.scala new file mode 100644 index 000000000000..7a79536738c3 --- /dev/null +++ b/tests/neg-macros/i9801b/Test_2.scala @@ -0,0 +1 @@ +def test: Unit = loop(4) // error