From 60b81b9e5aa2090ceee4af48d402ebdf47880d84 Mon Sep 17 00:00:00 2001 From: Hamza Remmal <56235032+hamzaremmal@users.noreply.github.com> Date: Mon, 6 Nov 2023 16:39:55 +0100 Subject: [PATCH] Add cache to avoid multiple definitions --- .../src/dotty/tools/dotc/transform/MacroAnnotations.scala | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/MacroAnnotations.scala b/compiler/src/dotty/tools/dotc/transform/MacroAnnotations.scala index 7e5f5dbace72..860f1a33e21e 100644 --- a/compiler/src/dotty/tools/dotc/transform/MacroAnnotations.scala +++ b/compiler/src/dotty/tools/dotc/transform/MacroAnnotations.scala @@ -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) @@ -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 @@ -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 @@ -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)