Skip to content

Commit d441dae

Browse files
jchybWojciechMazur
authored andcommitted
Fix erasure crash for Inlined rhs of a ctxfun closure
This is achieved by safely removing Inlined nodes at that point, in the same manner they would be removed later in `typedInlined`` in the same phase. [Cherry-picked f70ed41]
1 parent 000ae26 commit d441dae

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,8 @@ object Erasure {
936936
vparams = vparams :+ param
937937
if crCount == 1 then meth.rhs.changeOwnerAfter(meth.symbol, sym, erasurePhase)
938938
else skipContextClosures(meth.rhs, crCount - 1)
939+
case inlined: Inlined =>
940+
skipContextClosures(Inlines.dropInlined(inlined), crCount)
939941

940942
var rhs1 = skipContextClosures(ddef.rhs.asInstanceOf[Tree], contextResultCount(sym))
941943

tests/pos-macros/i16963/Macro_1.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.quoted.*
2+
3+
inline def myMacro = ${ myMacroExpr }
4+
5+
def myMacroExpr(using Quotes) =
6+
import quotes.reflect.*
7+
8+
'{ def innerMethod = (_: String) ?=> ???; () }.asTerm match
9+
case block @ Inlined(_, _, Block(List(defdef: DefDef), _)) =>
10+
val rhs =
11+
given Quotes = defdef.symbol.asQuotes
12+
'{ (x: String) ?=> ??? }.asTerm
13+
14+
Block(List(DefDef(defdef.symbol, _ => Some(rhs))), '{}.asTerm).asExprOf[Unit]

tests/pos-macros/i16963/Test_2.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def method: Unit = myMacro

0 commit comments

Comments
 (0)