Skip to content

Commit cd70cb2

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

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
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/Quotes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
5151
* Emits an error and throws if the expression does not represent a value or possibly contains side effects.
5252
* Otherwise returns the value.
5353
*/
54-
@deprecated("Use valueOrThrow", "3.0.0-RC3")
54+
@deprecated("Use valueOrThrow", "3.1.0")
5555
def valueOrError(using FromExpr[T]): T = valueOrAbort
5656

5757
/** Return the value of this expression.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package scala.quoted.runtime
22

33
/** Throwable used to stop the expansion of a macro after an error was reported */
4-
@deprecated("Use AbortExpansion", "3.0.0-RC3")
5-
class StopMacroExpansion extends Throwable
4+
@deprecated("Use AbortExpansion", "3.1.0")
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)