1
1
package io .bazel .rulesscala .dependencyanalyzer
2
2
3
+ import scala .collection .mutable
3
4
import scala .reflect .io .AbstractFile
4
5
import scala .tools .nsc .Global
5
6
@@ -10,6 +11,7 @@ class AstUsedJarFinder(
10
11
11
12
def findUsedJars : Map [AbstractFile , Global # Position ] = {
12
13
val jars = collection.mutable.Map [AbstractFile , global.Position ]()
14
+ val visitedTrees = mutable.Set .empty[Tree ]
13
15
14
16
def recordUse (source : AbstractFile , pos : Position ): Unit = {
15
17
// We prefer to report locations which have information (e.g.
@@ -94,12 +96,7 @@ class AstUsedJarFinder(
94
96
tree.attachments
95
97
.get[global.treeChecker.MacroExpansionAttachment ]
96
98
.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)
103
100
}
104
101
105
102
val shouldExamine =
@@ -133,7 +130,11 @@ class AstUsedJarFinder(
133
130
}
134
131
}
135
132
136
- tree.foreach(visitNode)
133
+ // handle possible cycles in macro expandees
134
+ if (! visitedTrees.contains(tree)) {
135
+ visitedTrees += tree
136
+ tree.foreach(visitNode)
137
+ }
137
138
}
138
139
139
140
currentRun.units.foreach { unit =>
0 commit comments