Skip to content

Commit ccf6c2a

Browse files
committed
Fix #9801: Make sure the errors are reported
1 parent a05fc4b commit ccf6c2a

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

compiler/src/dotty/tools/dotc/transform/Splicer.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ object Splicer {
6565
EmptyTree
6666
case ex: StopInterpretation =>
6767
report.error(ex.msg, ex.pos)
68-
EmptyTree
68+
ref(defn.Predef_undefined).withType(ErrorType(ex.msg))
6969
case NonFatal(ex) =>
7070
val msg =
7171
s"""Failed to evaluate macro.
7272
| Caused by ${ex.getClass}: ${if (ex.getMessage == null) "" else ex.getMessage}
7373
| ${ex.getStackTrace.takeWhile(_.getClassName != "dotty.tools.dotc.transform.Splicer$").drop(1).mkString("\n ")}
7474
""".stripMargin
7575
report.error(msg, pos)
76-
EmptyTree
76+
ref(defn.Predef_undefined).withType(ErrorType(msg))
7777
}
7878
}
7979

tests/neg-macros/i9801/Macro_1.scala

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import scala.quoted._
2+
3+
def f() = ()
4+
5+
def triggerStackOverflow(n: Int): Expr[Double] = {
6+
val r = triggerStackOverflow(n - 1)
7+
f()
8+
r
9+
}
10+
11+
inline def loop(inline prog: Double): Double = ${impl('prog)}
12+
13+
def impl(prog: Expr[Double])(using QuoteContext) : Expr[Double] =
14+
try {
15+
triggerStackOverflow(0)
16+
} catch {
17+
case e =>
18+
qctx.tasty.error(e.getMessage, prog.unseal.pos)
19+
'{ 42.0 }
20+
}

tests/neg-macros/i9801/Test_2.scala

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def test: Unit = loop(4) // error

tests/neg-macros/i9801b/Macro_1.scala

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.quoted._
2+
3+
def f() = ()
4+
5+
def triggerStackOverflow(n: Int): Expr[Double] = {
6+
val r = triggerStackOverflow(n - 1)
7+
f()
8+
r
9+
}
10+
11+
inline def loop(inline prog: Double): Double = ${impl('prog)}
12+
13+
def impl(prog: Expr[Double])(using QuoteContext) : Expr[Double] =
14+
triggerStackOverflow(0)

tests/neg-macros/i9801b/Test_2.scala

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def test: Unit = loop(4) // error

0 commit comments

Comments
 (0)