Skip to content

Commit 44aa3c6

Browse files
committed
Avoid crash after StopMacroExpansion
When a splice throws a StopMacroExpansion, it's replaced by an EmptyTree, which has NoType. Which means you can't cast it, as you can't call .asInstanceOf on it. So handle this before calling ensureConforms.
1 parent e994cf0 commit 44aa3c6

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Diff for: 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 || !inlined.tpe.exists 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

Diff for: 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")

Diff for: 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

0 commit comments

Comments
 (0)