Skip to content

Commit

Permalink
Fix Splicer.isEscapedVariable
Browse files Browse the repository at this point in the history
Consider that `val macro` expansion in the context can come from
an outer macro that is being expanded (i.e. this is a nested macro).
Nested macro expansion can occur when a macro summons an implicit macro.

Fixes partially scala#16835
  • Loading branch information
nicolasstucki committed Feb 6, 2023
1 parent a356581 commit d8faf57
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ object Splicer {
}
}

/** Checks that no symbol that whas generated within the macro expansion has an out of scope reference */
/** Checks that no symbol that was generated within the macro expansion has an out of scope reference */
def checkEscapedVariables(tree: Tree, expansionOwner: Symbol)(using Context): tree.type =
new TreeTraverser {
private[this] var locals = Set.empty[Symbol]
Expand Down Expand Up @@ -119,7 +119,10 @@ object Splicer {
sym.exists && !sym.is(Package)
&& 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
{ // symbol was generated within another macro expansion
x.is(Macro, butNot = Method) && x.name == nme.MACROkw &&
!ctx.owner.ownersIterator.contains(x)
}
)
&& !locals.contains(sym) // symbol is not in current scope
}.traverse(tree)
Expand Down

0 comments on commit d8faf57

Please sign in to comment.