diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 837cf95bab01..d89ba6128274 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -30,6 +30,7 @@ import collection.mutable import reporting.trace import util.Spans.Span import dotty.tools.dotc.transform.{Splicer, TreeMapWithStages} +import quoted.QuoteUtils object Inliner { import tpd._ @@ -520,7 +521,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { ref(rhsClsSym.sourceModule) else inlineCallPrefix - val binding = ValDef(selfSym.asTerm, rhs).withSpan(selfSym.span).setDefTree + val binding = ValDef(selfSym.asTerm, QuoteUtils.changeOwnerOfTree(rhs, selfSym)).withSpan(selfSym.span).setDefTree bindingsBuf += binding inlining.println(i"proxy at $level: $selfSym = ${bindingsBuf.last}") lastSelf = selfSym diff --git a/tests/pos-macros/i11251/Macro_1.scala b/tests/pos-macros/i11251/Macro_1.scala new file mode 100644 index 000000000000..0dcb53bb7acd --- /dev/null +++ b/tests/pos-macros/i11251/Macro_1.scala @@ -0,0 +1,29 @@ +package i11251 + +import scala.quoted._ + +class SL: + + inline def foo(inline step: Int => Int): SL = + val f = step + this + + def run1(): Unit = ??? + + inline def run(): Unit = + run1() + +// works +//object SL + +object X: + + inline def process[T](inline f:T) = ${ + processImpl[T]('f) + } + + def processImpl[T:Type](t:Expr[T])(using Quotes):Expr[T] = + import quotes.reflect._ + val checker = new TreeMap() {} + checker.transformTerm(t.asTerm)(Symbol.spliceOwner) + t diff --git a/tests/pos-macros/i11251/Test_2.scala b/tests/pos-macros/i11251/Test_2.scala new file mode 100644 index 000000000000..9445ff253d35 --- /dev/null +++ b/tests/pos-macros/i11251/Test_2.scala @@ -0,0 +1,12 @@ +package i11251 + + +object Main { + + def main(args:Array[String]):Unit = + val sl = new SL() + X.process( + sl.foo(x=>x+1).run() + ) + +}