Skip to content

Commit

Permalink
Add cache to avoid multiple definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal committed Nov 6, 2023
1 parent b0c190c commit 60b81b9
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,9 @@ class MacroAnnotations(phase: IdentityDenotTransformer):
insertedAfter = suffixed :: insertedAfter
for prefixedTree <- prefixed do
checkMacroDef(prefixedTree, tree, annot)
enterMissingSymbols(prefixedTree)
for suffixedTree <- suffixed do
checkMacroDef(suffixedTree, tree, annot)
enterMissingSymbols(suffixedTree)
TreeChecker.checkMacroGeneratedTree(tree, newTree)
enterMissingSymbols(newTree)
newTree
case (Nil, Nil) =>
report.error(i"Unexpected `Nil` returned by `(${annot.tree}).transform(..)` during macro expansion", annot.tree.srcPos)
Expand All @@ -82,6 +79,7 @@ class MacroAnnotations(phase: IdentityDenotTransformer):
insertedAfter.foreach(allTrees.++=)

val result = allTrees.result()
for tree <- result do enterMissingSymbols(tree)
debug.println(result.map(_.show).mkString("expanded to:\n", "\n", ""))
result

Expand Down Expand Up @@ -136,7 +134,7 @@ class MacroAnnotations(phase: IdentityDenotTransformer):
else if annotated.isClass && annotated.owner.is(Package) /*&& !sym.isClass*/ then
report.error(i"macro annotation can not add top-level ${sym.showKind}. $annot tried to add $sym.", annot.tree)

private def enterMissingSymbols(tree: MemberDef)(using Context) = new TreeTraverser {
private def enterMissingSymbols(tree: DefTree)(using Context) = new TreeTraverser {
def traverse(tree: tpd.Tree)(using Context): Unit = tree match
case tdef @ TypeDef(_, template: Template) =>
//for tree <- template.constr :: template.body do
Expand All @@ -146,7 +144,7 @@ class MacroAnnotations(phase: IdentityDenotTransformer):
report.error(em"Macro added a definition with the wrong owner - ${tree.symbol.owner} - ${tdef.symbol} in ${tree.source}")
else if !isSymbolInDecls(tree.symbol) then
tree.symbol.enteredAfter(phase)
traverseChildren(tree) // Taverse before or after dealing with this class?
traverseChildren(tree) // Traverse before or after dealing with this class?
case _ => traverseChildren(tree)
}.traverse(tree)

Expand Down

0 comments on commit 60b81b9

Please sign in to comment.