Skip to content

Commit c36c390

Browse files
authored
Avoid crash after StopMacroExpansion (#19883)
2 parents 736ea2a + 0fe0490 commit c36c390

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

compiler/src/dotty/tools/dotc/inlines/Inlines.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,14 @@ object Inlines:
494494

495495
// Take care that only argument bindings go into `bindings`, since positions are
496496
// different for bindings from arguments and bindings from body.
497-
val res = tpd.Inlined(call, bindings, expansion)
497+
val inlined = tpd.Inlined(call, bindings, expansion)
498498

499-
if !hasOpaqueProxies then res
499+
if !hasOpaqueProxies then inlined
500500
else
501501
val target =
502-
if inlinedMethod.is(Transparent) then call.tpe & res.tpe
502+
if inlinedMethod.is(Transparent) then call.tpe & inlined.tpe
503503
else call.tpe
504-
res.ensureConforms(target)
504+
inlined.ensureConforms(target)
505505
// Make sure that the sealing with the declared type
506506
// is type correct. Without it we might get problems since the
507507
// expression's type is the opaque alias but the call's type is

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ object Splicer {
7272
if !ctx.reporter.hasErrors then
7373
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.", splicePos)
7474
// errors have been emitted
75-
EmptyTree
75+
ref(defn.Predef_undefined).withType(ErrorType(em"macro expansion was stopped"))
7676
case ex: StopInterpretation =>
7777
report.error(ex.msg, ex.pos)
7878
ref(defn.Predef_undefined).withType(ErrorType(ex.msg))

tests/neg-macros/i19851/Macro_1.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.quoted.*
2+
3+
opaque type Box[A] = Any
4+
object Box:
5+
transparent inline def pack[A]: Nothing => Box[A] = ${ packImpl[A] }
6+
7+
private def packImpl[A](using Quotes, Type[A]): Expr[Nothing => Box[A]] =
8+
import quotes.reflect.*
9+
report.errorAndAbort("Not implemented")

tests/neg-macros/i19851/Test_2.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Test:
2+
def t1: Unit =
3+
Box.pack[Int] // error

tests/neg-macros/i9014b.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
|
88
| given_Bar
99
|
10-
| But given instance given_Bar does not match type Bar.
10+
| But macro expansion was stopped.

0 commit comments

Comments
 (0)