Skip to content

Commit f760199

Browse files
committed
fix #11251 (changeOwner of rhs of valdef for this proxy)
1 parent 261b280 commit f760199

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import collection.mutable
3030
import reporting.trace
3131
import util.Spans.Span
3232
import dotty.tools.dotc.transform.{Splicer, TreeMapWithStages}
33+
import quoted.QuoteUtils
3334

3435
object Inliner {
3536
import tpd._
@@ -520,7 +521,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
520521
ref(rhsClsSym.sourceModule)
521522
else
522523
inlineCallPrefix
523-
val binding = ValDef(selfSym.asTerm, rhs).withSpan(selfSym.span).setDefTree
524+
val binding = ValDef(selfSym.asTerm, QuoteUtils.changeOwnerOfTree(rhs, selfSym)).withSpan(selfSym.span).setDefTree
524525
bindingsBuf += binding
525526
inlining.println(i"proxy at $level: $selfSym = ${bindingsBuf.last}")
526527
lastSelf = selfSym

tests/pos-macros/i11251/Macro_1.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package i11251
2+
3+
import scala.quoted._
4+
5+
class SL:
6+
7+
inline def foo(inline step: Int => Int): SL =
8+
val f = step
9+
this
10+
11+
def run1(): Unit = ???
12+
13+
inline def run(): Unit =
14+
run1()
15+
16+
// works
17+
//object SL
18+
19+
object X:
20+
21+
inline def process[T](inline f:T) = ${
22+
processImpl[T]('f)
23+
}
24+
25+
def processImpl[T:Type](t:Expr[T])(using Quotes):Expr[T] =
26+
import quotes.reflect._
27+
val checker = new TreeMap() {}
28+
checker.transformTerm(t.asTerm)(Symbol.spliceOwner)
29+
t

tests/pos-macros/i11251/Test_2.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package i11251
2+
3+
4+
object Main {
5+
6+
def main(args:Array[String]):Unit =
7+
val sl = new SL()
8+
X.process(
9+
sl.foo(x=>x+1).run()
10+
)
11+
12+
}

0 commit comments

Comments
 (0)