Skip to content

Commit 4586e7a

Browse files
committed
Improve error handling of missuses of AbortExpansion
1 parent 2705092 commit 4586e7a

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ object Splicer {
6363
catch {
6464
case ex: CompilationUnit.SuspendException =>
6565
throw ex
66-
case ex: scala.quoted.runtime.AbortExpansion if ctx.reporter.hasErrors =>
66+
case ex: scala.quoted.runtime.AbortExpansion =>
67+
if !ctx.reporter.hasErrors then
68+
report.error("An AbortExpansion was thrown without any errors reported while expanding a macro. This macro has a bug.", splicePos)
6769
// errors have been emitted
6870
EmptyTree
6971
case ex: StopInterpretation =>

library/src/scala/quoted/runtime/StopMacroExpansion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ package scala.quoted.runtime
22

33
/** Throwable used to stop the expansion of a macro after an error was reported */
44
@deprecated("Use AbortExpansion", "3.0.0-RC3")
5-
class StopMacroExpansion extends Throwable
5+
class StopMacroExpansion extends AbortExpansion

tests/neg-macros/ill-abort.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
-- Error: tests/neg-macros/ill-abort/quoted_2.scala:1:15 ---------------------------------------------------------------
3+
1 |def test = fail() // error
4+
| ^^^^^^
5+
| An AbortExpansion was thrown without any errors reported while expanding a macro. This macro has a bug.
6+
| This location contains code that was inlined from quoted_1.scala:3
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted.*
2+
3+
inline def fail(): Unit = ${ impl }
4+
5+
private def impl(using Quotes) : Expr[Unit] =
6+
// should never be done without reporting error before (see docs)
7+
throw new scala.quoted.runtime.AbortExpansion
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def test = fail() // error

0 commit comments

Comments
 (0)