Skip to content

Commit 8ef2c5c

Browse files
authored
Fix erasure crash for Inlined rhs of a context function closure (#20398)
Fixes #16963 The regression here was caused by 229fdaa, by the changes to TreeInfo. Since the aim of that PR was to reduce unnecessary `Inlined` removal, instead of reintroducing `Inlined` node removal in `closureDef` in `TreeInfo` (which is used in many places in the compiler), we just remove it directly in erasure, where it would have been removed later in the same manner either way (in `typedInlined`).
2 parents c6faeb1 + f70ed41 commit 8ef2c5c

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,8 @@ object Erasure {
945945
vparams = vparams :+ param
946946
if crCount == 1 then meth.rhs.changeOwnerAfter(meth.symbol, sym, erasurePhase)
947947
else skipContextClosures(meth.rhs, crCount - 1)
948+
case inlined: Inlined =>
949+
skipContextClosures(Inlines.dropInlined(inlined), crCount)
948950

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

tests/pos-macros/i16963/Macro_1.scala

+14
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

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def method: Unit = myMacro

0 commit comments

Comments
 (0)