diff --git a/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala b/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala index a25f80da2786..1b354abf929f 100644 --- a/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala +++ b/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala @@ -98,7 +98,7 @@ object PickledQuotes { /** Replace all term holes with the spliced terms */ private def spliceTerms(tree: Tree, typeHole: TypeHole, termHole: ExprHole)(using Context): Tree = { - def evaluateHoles = new TreeMap { + def evaluateHoles = new TreeMapWithPreciseStatContexts { override def transform(tree: tpd.Tree)(using Context): tpd.Tree = tree match { case Hole(isTerm, idx, args, _) => inContext(SpliceScope.contextWithNewSpliceScope(tree.sourcePos)) { diff --git a/tests/pos-macros/i18358/Macro_1.scala b/tests/pos-macros/i18358/Macro_1.scala new file mode 100644 index 000000000000..7471bca97449 --- /dev/null +++ b/tests/pos-macros/i18358/Macro_1.scala @@ -0,0 +1,4 @@ +import scala.quoted.* +inline def generateCode: Unit = ${ testLocalDummyOwner } +def testLocalDummyOwner(using Quotes): Expr[Unit] = '{ trait E { $valInBlock } } +def valInBlock(using Quotes): Expr[Unit] = '{ val x: Int = 2; () } diff --git a/tests/pos-macros/i18358/Test_2.scala b/tests/pos-macros/i18358/Test_2.scala new file mode 100644 index 000000000000..7110731760a6 --- /dev/null +++ b/tests/pos-macros/i18358/Test_2.scala @@ -0,0 +1 @@ +def test = generateCode