Skip to content

Commit

Permalink
Improve error handling of missuses of AbortExpansion
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Apr 13, 2021
1 parent 2705092 commit 4586e7a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ object Splicer {
catch {
case ex: CompilationUnit.SuspendException =>
throw ex
case ex: scala.quoted.runtime.AbortExpansion if ctx.reporter.hasErrors =>
case ex: scala.quoted.runtime.AbortExpansion =>
if !ctx.reporter.hasErrors then
report.error("An AbortExpansion was thrown without any errors reported while expanding a macro. This macro has a bug.", splicePos)
// errors have been emitted
EmptyTree
case ex: StopInterpretation =>
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/quoted/runtime/StopMacroExpansion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package scala.quoted.runtime

/** Throwable used to stop the expansion of a macro after an error was reported */
@deprecated("Use AbortExpansion", "3.0.0-RC3")
class StopMacroExpansion extends Throwable
class StopMacroExpansion extends AbortExpansion
6 changes: 6 additions & 0 deletions tests/neg-macros/ill-abort.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

-- Error: tests/neg-macros/ill-abort/quoted_2.scala:1:15 ---------------------------------------------------------------
1 |def test = fail() // error
| ^^^^^^
| An AbortExpansion was thrown without any errors reported while expanding a macro. This macro has a bug.
| This location contains code that was inlined from quoted_1.scala:3
7 changes: 7 additions & 0 deletions tests/neg-macros/ill-abort/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted.*

inline def fail(): Unit = ${ impl }

private def impl(using Quotes) : Expr[Unit] =
// should never be done without reporting error before (see docs)
throw new scala.quoted.runtime.AbortExpansion
1 change: 1 addition & 0 deletions tests/neg-macros/ill-abort/quoted_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def test = fail() // error

0 comments on commit 4586e7a

Please sign in to comment.