diff --git a/community-build/community-projects/sourcecode b/community-build/community-projects/sourcecode index c913da4552a0..2c0ae1b34aad 160000 --- a/community-build/community-projects/sourcecode +++ b/community-build/community-projects/sourcecode @@ -1 +1 @@ -Subproject commit c913da4552a0ce8be1526447b614fb5de01bc392 +Subproject commit 2c0ae1b34aada9ef1e4e37b507df1cd7005fe067 diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index 7a41c81bd288..ddab4c1e04fe 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -41,7 +41,7 @@ object Splicer { case Quoted(quotedTree) => quotedTree case _ => val interpreter = new Interpreter(pos, classLoader) - val macroOwner = ctx.newSymbol(ctx.owner, NameKinds.UniqueName.fresh(nme.MACROkw), Synthetic, defn.AnyType, coord = tree.span) + val macroOwner = ctx.newSymbol(ctx.owner, nme.MACROkw, Macro | Synthetic, defn.AnyType, coord = tree.span) try { given Context = ctx.withOwner(macroOwner) // Some parts of the macro are evaluated during the unpickling performed in quotedExprToTree @@ -100,7 +100,10 @@ object Splicer { traverseChildren(tree) private def isEscapedVariable(sym: Symbol)(given ctx: Context): Boolean = sym.exists && !sym.is(Package) - && sym.owner.ownersIterator.contains(expansionOwner) // symbol was generated within the macro expansion + && sym.owner.ownersIterator.exists(x => + x == expansionOwner || // symbol was generated within this macro expansion + x.is(Macro, butNot = Method) && x.name == nme.MACROkw // symbol was generated within another macro expansion + ) && !locals.contains(sym) // symbol is not in current scope }.traverse(tree) tree diff --git a/tests/neg-macros/i7142h/Macro_1.scala b/tests/neg-macros/i7142h/Macro_1.scala new file mode 100644 index 000000000000..f33e6410a94a --- /dev/null +++ b/tests/neg-macros/i7142h/Macro_1.scala @@ -0,0 +1,11 @@ +package macros +import scala.quoted._ + +var saved = Option.empty[Expr[Int]] + +def oops(given QuoteContext) = { + if (saved.isEmpty) '{ (x: Int) => ${ saved = Some('{x}); 'x } } + else saved.get +} + +inline def test = ${oops} diff --git a/tests/neg-macros/i7142h/Test_2.scala b/tests/neg-macros/i7142h/Test_2.scala new file mode 100644 index 000000000000..4726f1d3d14c --- /dev/null +++ b/tests/neg-macros/i7142h/Test_2.scala @@ -0,0 +1,4 @@ +object Test { + macros.test + macros.test // error +} diff --git a/tests/run-custom-args/Yretain-trees/tasty-extractors-owners.check b/tests/run-custom-args/Yretain-trees/tasty-extractors-owners.check index c42e3ffd63b2..5e16ce08121f 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-extractors-owners.check +++ b/tests/run-custom-args/Yretain-trees/tasty-extractors-owners.check @@ -1,5 +1,5 @@ foo -ValDef("macro$1", Inferred(), None) +ValDef("macro", Inferred(), None) bar DefDef("foo", Nil, Nil, Inferred(), None) @@ -8,7 +8,7 @@ bar2 DefDef("foo", Nil, Nil, Inferred(), None) foo2 -ValDef("macro$1", Inferred(), None) +ValDef("macro", Inferred(), None) baz ValDef("foo2", Inferred(), None) diff --git a/tests/run-macros/tasty-location.check b/tests/run-macros/tasty-location.check index c066a966ebdb..53e831291709 100644 --- a/tests/run-macros/tasty-location.check +++ b/tests/run-macros/tasty-location.check @@ -1,6 +1,6 @@ -foo Location(List(Test$, loc1, macro$1)) -foo Location(List(Test$, main, macro$2)) -foo Location(List(Test$, main, macro$3)) -foo Location(List(Test$, main, bar, macro$4)) -foo Location(List(Test$, main, bar, baz, macro$5)) -foo Location(List(Test$, main, f, $anonfun, macro$6)) +foo Location(List(Test$, loc1, macro)) +foo Location(List(Test$, main, macro)) +foo Location(List(Test$, main, macro)) +foo Location(List(Test$, main, bar, macro)) +foo Location(List(Test$, main, bar, baz, macro)) +foo Location(List(Test$, main, f, $anonfun, macro))