11package io .bazel .rulesscala .dependencyanalyzer
22
3+ import scala .collection .mutable
34import scala .reflect .io .AbstractFile
45import scala .tools .nsc .Global
56
@@ -10,6 +11,7 @@ class AstUsedJarFinder(
1011
1112 def findUsedJars : Map [AbstractFile , Global # Position ] = {
1213 val jars = collection.mutable.Map [AbstractFile , global.Position ]()
14+ val visitedTrees = mutable.Set .empty[Tree ]
1315
1416 def recordUse (source : AbstractFile , pos : Position ): Unit = {
1517 // We prefer to report locations which have information (e.g.
@@ -94,12 +96,7 @@ class AstUsedJarFinder(
9496 tree.attachments
9597 .get[global.treeChecker.MacroExpansionAttachment ]
9698 .foreach { attach =>
97- // When we explore the original, the original also has
98- // this attachment. So we should not examine the original
99- // again if so.
100- if (attach.expandee != tree) {
101- fullyExploreTree(attach.expandee)
102- }
99+ fullyExploreTree(attach.expandee)
103100 }
104101
105102 val shouldExamine =
@@ -133,7 +130,11 @@ class AstUsedJarFinder(
133130 }
134131 }
135132
136- tree.foreach(visitNode)
133+ // handle possible cycles in macro expandees
134+ if (! visitedTrees.contains(tree)) {
135+ visitedTrees += tree
136+ tree.foreach(visitNode)
137+ }
137138 }
138139
139140 currentRun.units.foreach { unit =>
0 commit comments