Skip to content

Commit d045ea6

Browse files
committed
Resolve overriding early
1 parent 6082984 commit d045ea6

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

compiler/src/dotty/tools/dotc/transform/init/Checking.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ object Checking {
231231
val cls = pot match
232232
case hot: Hot => hot.classSymbol
233233
case obj: Global => obj.moduleClass
234-
state.dependencies += StaticCall(cls, sym)(pot.source)
234+
val target = resolve(cls, sym)
235+
state.dependencies += StaticCall(cls, target)(pot.source)
235236
Errors.empty
236237

237238
case _: Cold =>
@@ -330,19 +331,23 @@ object Checking {
330331
Errors.empty
331332

332333
case MethodReturn(hot: Hot, sym) =>
333-
state.dependencies += ProxyUsage(hot.classSymbol, sym)(pot.source)
334+
val target = resolve(hot.classSymbol, sym)
335+
state.dependencies += ProxyUsage(hot.classSymbol, target)(pot.source)
334336
Errors.empty
335337

336338
case MethodReturn(obj: Global, sym) =>
337-
state.dependencies += ProxyUsage(obj.moduleClass, sym)(pot.source)
339+
val target = resolve(obj.moduleClass, sym)
340+
state.dependencies += ProxyUsage(obj.moduleClass, target)(pot.source)
338341
Errors.empty
339342

340343
case FieldReturn(hot: Hot, sym) =>
341-
state.dependencies += ProxyUsage(hot.classSymbol, sym)(pot.source)
344+
val target = resolve(hot.classSymbol, sym)
345+
state.dependencies += ProxyUsage(hot.classSymbol, target)(pot.source)
342346
Errors.empty
343347

344348
case FieldReturn(obj: Global, sym) =>
345-
state.dependencies += ProxyUsage(obj.moduleClass, sym)(pot.source)
349+
val target = resolve(obj.moduleClass, sym)
350+
state.dependencies += ProxyUsage(obj.moduleClass, target)(pot.source)
346351
Errors.empty
347352

348353
case Fun(pots, effs) =>

compiler/src/dotty/tools/dotc/transform/init/CycleChecker.scala

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,18 @@ case class InstanceUsage(symbol: Symbol)(val source: Tree) extends Dependency {
6565
*
6666
* The method can be either on a static object or on a hot object.
6767
* The target of the call is determined statically.
68+
*
69+
* Note: Virtual method resolution should have been performed for the target.
70+
*
6871
*/
6972
case class StaticCall(cls: ClassSymbol, symbol: Symbol)(val source: Tree) extends Dependency {
7073
def show(using Context): String = "StaticCall(" + cls.show + ", " + symbol.show + ")"
7174
}
7275

73-
/** A static method call result is used */
76+
/** A static method call result is used
77+
*
78+
* Note: Virtual method resolution should have been performed for the target.
79+
*/
7480
case class ProxyUsage(cls: ClassSymbol, symbol: Symbol)(val source: Tree) extends Dependency {
7581
def show(using Context): String = "ProxyUsage(" + cls.show + ", " + symbol.show + ")"
7682
}
@@ -166,17 +172,17 @@ class CycleChecker(cache: Cache) {
166172
}
167173

168174
private def checkStaticCall(dep: StaticCall)(using Context, State): List[Error] =
169-
if !classesInCurrentRun.contains(dep.cls) then
170-
Util.traceIndented("skip " + dep.cls.show + " which is not in current run ", init)
175+
if !classesInCurrentRun.contains(dep.cls) || !classesInCurrentRun.contains(dep.symbol.owner) then
176+
Util.traceIndented("skip " + dep.show + " which is not in current run ", init)
171177
Nil
172178
else {
173179
val deps = methodDependencies(dep)
174180
deps.flatMap(check(_))
175181
}
176182

177183
private def checkProxyUsage(dep: ProxyUsage)(using Context, State): List[Error] =
178-
if !classesInCurrentRun.contains(dep.cls) then
179-
Util.traceIndented("skip " + dep.cls.show + " which is not in current run ", init)
184+
if !classesInCurrentRun.contains(dep.cls) || !classesInCurrentRun.contains(dep.symbol.owner) then
185+
Util.traceIndented("skip " + dep.show + " which is not in current run ", init)
180186
Nil
181187
else {
182188
val deps = proxyDependencies(dep)
@@ -239,8 +245,7 @@ class CycleChecker(cache: Cache) {
239245
}
240246

241247
val pot = Hot(dep.cls)(dep.source)
242-
val target = Util.resolve(dep.cls, dep.symbol)
243-
val effs = pot.potentialsOf(target)(using env).promote(dep.source)
248+
val effs = pot.potentialsOf(dep.symbol)(using env).promote(dep.source)
244249

245250
val errs = effs.flatMap(Checking.check(_)(using state))
246251
assert(errs.isEmpty, "unexpected errors: " + Errors.show(errs.toList))
@@ -355,8 +360,7 @@ class CycleChecker(cache: Cache) {
355360
}
356361

357362
val pot = Hot(dep.cls)(dep.source)
358-
val target = Util.resolve(dep.cls, dep.symbol)
359-
val effs = pot.effectsOf(target)(using env)
363+
val effs = pot.effectsOf(dep.symbol)(using env)
360364

361365
val errs = effs.flatMap(Checking.check(_)(using state))
362366
assert(errs.isEmpty, "unexpected errors: " + Errors.show(errs.toList))

0 commit comments

Comments
 (0)