@@ -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 (visited : mutable. 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 = " "
@@ -74,7 +73,7 @@ class CheckGlobal {
74
73
private val summaryCache = mutable.Map .empty[Symbol , List [Dependency ]]
75
74
76
75
def check (obj : Symbol )(using Context ): Unit = trace(" checking " + obj.show, init) {
77
- checkDependencies(obj, State (visited = Set .empty, path = Vector .empty, obj)) match
76
+ checkDependencies(obj, State (visited = mutable. Set .empty, path = Vector .empty, obj)) match
78
77
case Some (err) => err.issue
79
78
case _ =>
80
79
}
@@ -85,7 +84,7 @@ class CheckGlobal {
85
84
else if state.visited.contains(sym) then
86
85
None
87
86
else
88
- state.visited = state.visited + sym
87
+ state.visited += sym
89
88
checkDependencies(sym, state)
90
89
}
91
90
@@ -96,8 +95,9 @@ class CheckGlobal {
96
95
var res : Option [Error ] = None
97
96
// TODO: stop early
98
97
deps.foreach { dep =>
99
- val state2 : State = state.copy(path = state.path :+ dep.source)
100
- if res.isEmpty then res = check(dep.sym, state2)
98
+ if res.isEmpty then
99
+ val state2 : State = state.copy(path = state.path :+ dep.source)
100
+ res = check(dep.sym, state2)
101
101
}
102
102
res
103
103
}
@@ -110,29 +110,50 @@ class CheckGlobal {
110
110
if (cls.defTree.isEmpty) Nil
111
111
else if (summaryCache.contains(cls)) summaryCache(cls)
112
112
else {
113
- val cdef = cls.defTree.asInstanceOf [tpd. TypeDef ]
114
- val tpl = cdef.rhs.asInstanceOf [tpd. Template ]
113
+ val cdef = cls.defTree.asInstanceOf [TypeDef ]
114
+ val tpl = cdef.rhs.asInstanceOf [Template ]
115
115
var dependencies : List [Dependency ] = Nil
116
- val traverser = new tpd. TreeTraverser {
117
- override def traverse (tree : tpd. Tree )(using Context ): Unit =
116
+ val traverser = new TreeTraverser {
117
+ override def traverse (tree : Tree )(using Context ): Unit =
118
118
tree match {
119
- case tree : tpd. RefTree if isStaticObjectRef(tree.symbol) =>
119
+ case tree : RefTree if isStaticObjectRef(tree.symbol) =>
120
120
dependencies = Dependency (tree.symbol, tree) :: dependencies
121
121
122
- case tdef : tpd. TypeDef =>
122
+ case tdef : TypeDef =>
123
123
// don't go into nested classes
124
124
125
- case tree : tpd. New =>
125
+ case tree : New =>
126
126
dependencies = Dependency (tree.tpe.classSymbol, tree) :: dependencies
127
127
128
128
case _ =>
129
129
traverseChildren(tree)
130
130
}
131
131
}
132
132
133
+ def typeRefOf (tp : Type ): TypeRef = tp.dealias.typeConstructor match {
134
+ case tref : TypeRef => tref
135
+ case hklambda : HKTypeLambda => typeRefOf(hklambda.resType)
136
+ }
137
+
138
+ def addStaticOuterDep (tp : Type , source : Tree ): Unit =
139
+ tp match
140
+ case NoPrefix =>
141
+ case tmref : TermRef =>
142
+ if isStaticObjectRef(tmref.symbol) then
143
+ dependencies = Dependency (tmref.symbol, source) :: dependencies
144
+ case ThisType (tref) =>
145
+ val obj = tref.symbol.sourceModule
146
+ if isStaticObjectRef(obj) then
147
+ dependencies = Dependency (obj, source) :: dependencies
148
+ case _ =>
149
+ throw new Exception (" unexpected type: " + tp)
150
+
133
151
// TODO: the traverser might create duplicate entries for parents
134
152
tpl.parents.foreach { tree =>
135
- dependencies = Dependency (tree.tpe.classSymbol, tree) :: dependencies
153
+ val tp = tree.tpe
154
+ val tref = typeRefOf(tp)
155
+ dependencies = Dependency (tp.classSymbol, tree) :: dependencies
156
+ addStaticOuterDep(tref.prefix, tree)
136
157
}
137
158
138
159
traverser.traverse(tpl)
0 commit comments