@@ -41,13 +41,13 @@ object Splicer {
41
41
case Quoted (quotedTree) => quotedTree
42
42
case _ =>
43
43
val interpreter = new Interpreter (pos, classLoader)
44
- val macroOwner = ctx.newSymbol(ctx.owner, NameKinds . UniqueName .fresh( nme.MACROkw ), Synthetic , defn.AnyType , coord = tree.span)
44
+ val macroOwner = ctx.newSymbol(ctx.owner, nme.MACROkw , Macro | Synthetic , defn.AnyType , coord = tree.span)
45
45
try {
46
46
given Context = ctx.withOwner(macroOwner)
47
47
// Some parts of the macro are evaluated during the unpickling performed in quotedExprToTree
48
48
val interpretedExpr = interpreter.interpret[scala.quoted.QuoteContext => scala.quoted.Expr [Any ]](tree)
49
49
val interpretedTree = interpretedExpr.fold(tree)(macroClosure => PickledQuotes .quotedExprToTree(macroClosure(QuoteContext ())))
50
- checkEscapedVariables(interpretedTree, macroOwner ).changeOwner(macroOwner, ctx.owner)
50
+ checkEscapedVariables(interpretedTree).changeOwner(macroOwner, ctx.owner)
51
51
}
52
52
catch {
53
53
case ex : CompilationUnit .SuspendException =>
@@ -70,7 +70,7 @@ object Splicer {
70
70
}
71
71
72
72
/** Checks that no symbol that whas generated within the macro expansion has an out of scope reference */
73
- def checkEscapedVariables (tree : Tree , expansionOwner : Symbol )(given ctx : Context ): tree.type =
73
+ def checkEscapedVariables (tree : Tree )(given ctx : Context ): tree.type =
74
74
new TreeTraverser {
75
75
private [this ] var locals = Set .empty[Symbol ]
76
76
private def markSymbol (sym : Symbol )(implicit ctx : Context ): Unit =
@@ -100,7 +100,7 @@ object Splicer {
100
100
traverseChildren(tree)
101
101
private def isEscapedVariable (sym : Symbol )(given ctx : Context ): Boolean =
102
102
sym.exists && ! sym.is(Package )
103
- && sym.owner.ownersIterator.contains(expansionOwner) // symbol was generated within the macro expansion
103
+ && sym.owner.ownersIterator.exists(x => x.is( Macro , butNot = Method ) && x.name == nme. MACROkw ) // symbol was generated within a macro expansion
104
104
&& ! locals.contains(sym) // symbol is not in current scope
105
105
}.traverse(tree)
106
106
tree
0 commit comments