Skip to content

Commit 56415fb

Browse files
authored
Backport "Fix owner of splices in class statements" to LTS (#19153)
Backports #18359 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 9713d4e + 5a4d683 commit 56415fb

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ object PickledQuotes {
9898

9999
/** Replace all term holes with the spliced terms */
100100
private def spliceTerms(tree: Tree, typeHole: TypeHole, termHole: ExprHole)(using Context): Tree = {
101-
def evaluateHoles = new TreeMap {
101+
def evaluateHoles = new TreeMapWithPreciseStatContexts {
102102
override def transform(tree: tpd.Tree)(using Context): tpd.Tree = tree match {
103103
case Hole(isTerm, idx, args, _) =>
104104
inContext(SpliceScope.contextWithNewSpliceScope(tree.sourcePos)) {

tests/pos-macros/i18358/Macro_1.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import scala.quoted.*
2+
inline def generateCode: Unit = ${ testLocalDummyOwner }
3+
def testLocalDummyOwner(using Quotes): Expr[Unit] = '{ trait E { $valInBlock } }
4+
def valInBlock(using Quotes): Expr[Unit] = '{ val x: Int = 2; () }

tests/pos-macros/i18358/Test_2.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def test = generateCode

0 commit comments

Comments
 (0)