Skip to content

Commit

Permalink
Fix erasure crash for Inlined rhs of a context function closure (#20398)
Browse files Browse the repository at this point in the history
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`).
  • Loading branch information
hamzaremmal authored May 20, 2024
2 parents c6faeb1 + f70ed41 commit 8ef2c5c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,8 @@ object Erasure {
vparams = vparams :+ param
if crCount == 1 then meth.rhs.changeOwnerAfter(meth.symbol, sym, erasurePhase)
else skipContextClosures(meth.rhs, crCount - 1)
case inlined: Inlined =>
skipContextClosures(Inlines.dropInlined(inlined), crCount)

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

Expand Down
14 changes: 14 additions & 0 deletions tests/pos-macros/i16963/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import scala.quoted.*

inline def myMacro = ${ myMacroExpr }

def myMacroExpr(using Quotes) =
import quotes.reflect.*

'{ def innerMethod = (_: String) ?=> ???; () }.asTerm match
case block @ Inlined(_, _, Block(List(defdef: DefDef), _)) =>
val rhs =
given Quotes = defdef.symbol.asQuotes
'{ (x: String) ?=> ??? }.asTerm

Block(List(DefDef(defdef.symbol, _ => Some(rhs))), '{}.asTerm).asExprOf[Unit]
1 change: 1 addition & 0 deletions tests/pos-macros/i16963/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def method: Unit = myMacro

0 comments on commit 8ef2c5c

Please sign in to comment.