Skip to content

Commit

Permalink
Avoid crash after StopMacroExpansion (scala#19883)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Mar 6, 2024
2 parents 736ea2a + 0fe0490 commit c36c390
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/inlines/Inlines.scala
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,14 @@ object Inlines:

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

if !hasOpaqueProxies then res
if !hasOpaqueProxies then inlined
else
val target =
if inlinedMethod.is(Transparent) then call.tpe & res.tpe
if inlinedMethod.is(Transparent) then call.tpe & inlined.tpe
else call.tpe
res.ensureConforms(target)
inlined.ensureConforms(target)
// Make sure that the sealing with the declared type
// is type correct. Without it we might get problems since the
// expression's type is the opaque alias but the call's type is
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ object Splicer {
if !ctx.reporter.hasErrors then
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)
// errors have been emitted
EmptyTree
ref(defn.Predef_undefined).withType(ErrorType(em"macro expansion was stopped"))
case ex: StopInterpretation =>
report.error(ex.msg, ex.pos)
ref(defn.Predef_undefined).withType(ErrorType(ex.msg))
Expand Down
9 changes: 9 additions & 0 deletions tests/neg-macros/i19851/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import scala.quoted.*

opaque type Box[A] = Any
object Box:
transparent inline def pack[A]: Nothing => Box[A] = ${ packImpl[A] }

private def packImpl[A](using Quotes, Type[A]): Expr[Nothing => Box[A]] =
import quotes.reflect.*
report.errorAndAbort("Not implemented")
3 changes: 3 additions & 0 deletions tests/neg-macros/i19851/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Test:
def t1: Unit =
Box.pack[Int] // error
2 changes: 1 addition & 1 deletion tests/neg-macros/i9014b.check
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
|
| given_Bar
|
| But given instance given_Bar does not match type Bar.
| But macro expansion was stopped.

0 comments on commit c36c390

Please sign in to comment.