Skip to content

Commit c848109

Browse files
dwijnandWojciechMazur
authored andcommitted
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. [Cherry-picked 44aa3c6]
1 parent b48eee3 commit c848109

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
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 || !inlined.tpe.exists 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

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

0 commit comments

Comments
 (0)