@@ -12,8 +12,7 @@ import printing.SyntaxHighlighting
12
12
import reporting .trace
13
13
import config .Printers .init
14
14
15
- import ast .Trees ._
16
- import ast .tpd
15
+ import ast .tpd ._
17
16
18
17
import scala .collection .mutable
19
18
@@ -37,10 +36,10 @@ import scala.collection.mutable
37
36
* compiled projects.
38
37
*/
39
38
class CheckGlobal {
40
- case class Dependency (sym : Symbol , source : tpd. Tree )
39
+ case class Dependency (sym : Symbol , source : Tree )
41
40
42
41
/** Checking state */
43
- case class State (var visited : Set [Symbol ], path : Vector [tpd. Tree ], obj : Symbol ) {
42
+ case class State (var visited : Set [Symbol ], path : Vector [Tree ], obj : Symbol ) {
44
43
def cyclicPath (using Context ): String = if (path.isEmpty) " " else " Cyclic path:\n " + {
45
44
var indentCount = 0
46
45
var last : String = " "
@@ -110,29 +109,50 @@ class CheckGlobal {
110
109
if (cls.defTree.isEmpty) Nil
111
110
else if (summaryCache.contains(cls)) summaryCache(cls)
112
111
else {
113
- val cdef = cls.defTree.asInstanceOf [tpd. TypeDef ]
114
- val tpl = cdef.rhs.asInstanceOf [tpd. Template ]
112
+ val cdef = cls.defTree.asInstanceOf [TypeDef ]
113
+ val tpl = cdef.rhs.asInstanceOf [Template ]
115
114
var dependencies : List [Dependency ] = Nil
116
- val traverser = new tpd. TreeTraverser {
117
- override def traverse (tree : tpd. Tree )(using Context ): Unit =
115
+ val traverser = new TreeTraverser {
116
+ override def traverse (tree : Tree )(using Context ): Unit =
118
117
tree match {
119
- case tree : tpd. RefTree if isStaticObjectRef(tree.symbol) =>
118
+ case tree : RefTree if isStaticObjectRef(tree.symbol) =>
120
119
dependencies = Dependency (tree.symbol, tree) :: dependencies
121
120
122
- case tdef : tpd. TypeDef =>
121
+ case tdef : TypeDef =>
123
122
// don't go into nested classes
124
123
125
- case tree : tpd. New =>
124
+ case tree : New =>
126
125
dependencies = Dependency (tree.tpe.classSymbol, tree) :: dependencies
127
126
128
127
case _ =>
129
128
traverseChildren(tree)
130
129
}
131
130
}
132
131
132
+ def typeRefOf (tp : Type ): TypeRef = tp.dealias.typeConstructor match {
133
+ case tref : TypeRef => tref
134
+ case hklambda : HKTypeLambda => typeRefOf(hklambda.resType)
135
+ }
136
+
137
+ def addStaticOuterDep (tp : Type , source : Tree ): Unit =
138
+ tp match
139
+ case NoPrefix =>
140
+ case tmref : TermRef =>
141
+ if isStaticObjectRef(tmref.symbol) then
142
+ dependencies = Dependency (tmref.symbol, source) :: dependencies
143
+ case ThisType (tref) =>
144
+ val obj = tref.symbol.sourceModule
145
+ if isStaticObjectRef(obj) then
146
+ dependencies = Dependency (obj, source) :: dependencies
147
+ case _ =>
148
+ throw new Exception (" unexpected type: " + tp)
149
+
133
150
// TODO: the traverser might create duplicate entries for parents
134
151
tpl.parents.foreach { tree =>
135
- dependencies = Dependency (tree.tpe.classSymbol, tree) :: dependencies
152
+ val tp = tree.tpe
153
+ val tref = typeRefOf(tp)
154
+ dependencies = Dependency (tp.classSymbol, tree) :: dependencies
155
+ addStaticOuterDep(tref.prefix, tree)
136
156
}
137
157
138
158
traverser.traverse(tpl)
0 commit comments