Skip to content

Commit 5a4d683

Browse files
nicolasstuckiKordyjan
authored andcommitted
Fix owner of spices in class statements
Fixes #18358 [Cherry-picked 525e93c]
1 parent 0c0b48d commit 5a4d683

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)