Skip to content

Commit c9badbc

Browse files
committed
Allow macro annotations to recover from suspension
1 parent bed0e86 commit c9badbc

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Diff for: compiler/src/dotty/tools/dotc/inlines/Inliner.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -1083,9 +1083,7 @@ class Inliner(val call: tpd.Tree)(using Context):
10831083
hints.nn += i"suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}"
10841084
if suspendable then
10851085
if ctx.settings.YnoSuspendedUnits.value then
1086-
return ref(defn.Predef_undefined)
1087-
.withType(ErrorType(em"could not expand macro, suspended units are disabled by -Yno-suspended-units"))
1088-
.withSpan(splicePos.span)
1086+
return errorTree(ref(defn.Predef_undefined), em"could not expand macro, suspended units are disabled by -Yno-suspended-units", splicePos)
10891087
else
10901088
ctx.compilationUnit.suspend(hints.nn.toList.mkString(", ")) // this throws a SuspendException
10911089

Diff for: compiler/src/dotty/tools/dotc/transform/MacroAnnotations.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ object MacroAnnotations:
127127
// Replace this case with the nested cases.
128128
case ex0: InvocationTargetException =>
129129
ex0.getCause match
130+
case ex: CompilationUnit.SuspendException =>
131+
throw ex
130132
case ex: scala.quoted.runtime.StopMacroExpansion =>
131133
if !ctx.reporter.hasErrors then
132134
report.error("Macro expansion was aborted by the macro without any errors reported. Macros should issue errors to end-users when aborting a macro expansion with StopMacroExpansion.", annot.tree)
@@ -137,7 +139,7 @@ object MacroAnnotations:
137139
val stack0 = ex.getStackTrace.takeWhile(_.getClassName != this.getClass().getName())
138140
val stack = stack0.take(1 + stack0.lastIndexWhere(_.getMethodName == "transform"))
139141
val msg =
140-
em"""Failed to evaluate macro.
142+
em"""Failed to evaluate macro annotation '$annot'.
141143
| Caused by ${ex.getClass}: ${if (ex.getMessage == null) "" else ex.getMessage}
142144
| ${stack.mkString("\n ")}
143145
|"""

0 commit comments

Comments
 (0)