Skip to content

Commit

Permalink
Fix #9801: Make sure the errors are reported
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Sep 17, 2020
1 parent a05fc4b commit ccf6c2a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ 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.
| Caused by ${ex.getClass}: ${if (ex.getMessage == null) "" else ex.getMessage}
| ${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))
}
}

Expand Down
20 changes: 20 additions & 0 deletions tests/neg-macros/i9801/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -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 }
}
1 change: 1 addition & 0 deletions tests/neg-macros/i9801/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def test: Unit = loop(4) // error
14 changes: 14 additions & 0 deletions tests/neg-macros/i9801b/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions tests/neg-macros/i9801b/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def test: Unit = loop(4) // error

0 comments on commit ccf6c2a

Please sign in to comment.