Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport "Avoid crash after StopMacroExpansion" to LTS #20979

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -449,14 +449,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.