Skip to content

Commit faa98f4

Browse files
committed
Add cache to avoid multiple definitions
1 parent b0c190c commit faa98f4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

compiler/src/dotty/tools/dotc/transform/MacroAnnotations.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class MacroAnnotations(phase: IdentityDenotTransformer):
2828
import tpd.*
2929
import MacroAnnotations.*
3030

31+
private val willBeEntered = new collection.mutable.HashSet[Symbol]
32+
3133
/** Expands every macro annotation that is on this tree.
3234
* Returns a list with transformed definition and any added definitions.
3335
*/
@@ -144,7 +146,9 @@ class MacroAnnotations(phase: IdentityDenotTransformer):
144146
for tree <- template.body do
145147
if tree.symbol.owner != tdef.symbol then
146148
report.error(em"Macro added a definition with the wrong owner - ${tree.symbol.owner} - ${tdef.symbol} in ${tree.source}")
147-
else if !isSymbolInDecls(tree.symbol) then
149+
else if !willBeEntered(tree.symbol) && !isSymbolInDecls(tree.symbol) then
150+
// Add a cache to avoid entering the same symbol twice in case of multiple macro annotatitions
151+
willBeEntered.add(tree.symbol)
148152
tree.symbol.enteredAfter(phase)
149153
traverseChildren(tree) // Taverse before or after dealing with this class?
150154
case _ => traverseChildren(tree)

0 commit comments

Comments
 (0)