Skip to content

Commit 7c1bb85

Browse files
Backport "Fix erasure crash for Inlined rhs of a context function closure" to LTS (#21114)
Backports #20398 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 1537ae1 + d441dae commit 7c1bb85

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)