Skip to content

Commit 77048cc

Browse files
Backport "Avoid crash after StopMacroExpansion" to LTS (#20979)
Backports #19883 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 1c11610 + 37abd28 commit 77048cc

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
@@ -449,14 +449,14 @@ object Inlines:
449449

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

454-
if !hasOpaqueProxies then res
454+
if !hasOpaqueProxies then inlined
455455
else
456456
val target =
457-
if inlinedMethod.is(Transparent) then call.tpe & res.tpe
457+
if inlinedMethod.is(Transparent) then call.tpe & inlined.tpe
458458
else call.tpe
459-
res.ensureConforms(target)
459+
inlined.ensureConforms(target)
460460
// Make sure that the sealing with the declared type
461461
// is type correct. Without it we might get problems since the
462462
// 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)