Skip to content

Commit ec5c7ba

Browse files
committed
Fix crash in compiling Dotty
1 parent 2e45946 commit ec5c7ba

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ object Checking {
3838
parentsInited: mutable.Set[ClassSymbol],
3939
safePromoted: mutable.Set[Potential], // Potentials that can be safely promoted
4040
dependencies: mutable.Set[Dependency], // if the current class is a static object, its dependencies
41-
env: Env
41+
env: Env,
42+
init: Boolean = false // whether object is initialized, used in CycleChecker
4243
) {
4344
def withOwner[T](sym: Symbol)(op: State ?=> T): T =
4445
val state = this.copy(env = env.withOwner(sym))
@@ -48,7 +49,7 @@ object Checking {
4849

4950

5051
def isFieldInitialized(field: Symbol): Boolean =
51-
fieldsInited.contains(field)
52+
init || fieldsInited.contains(field)
5253

5354
def visit[T](eff: Effect)(op: State ?=> T): T =
5455
val state: State = this.copy(path = path :+ eff.source, visited = this.visited + eff)

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class CycleChecker(cache: Cache) {
226226
}
227227

228228
private def proxyDependencies(dep: ProxyUsage)(using Context): List[Dependency] = trace("dependencies of " + dep.symbol.show, init, _.asInstanceOf[List[Dependency]].map(_.show).toString) {
229-
if (proxyCache.contains(dep.symbol)) summaryCache(dep.symbol)
229+
if (proxyCache.contains(dep.symbol)) proxyCache(dep.symbol)
230230
else trace("summary for " + dep.symbol.show) {
231231
val env = Env(ctx.withOwner(dep.cls), cache)
232232
val state = new Checking.State(
@@ -350,24 +350,23 @@ class CycleChecker(cache: Cache) {
350350

351351
private def analyzeMethod(dep: StaticCall)(using Context): List[Dependency] = {
352352
val env = Env(ctx.withOwner(dep.cls), cache)
353-
val state = new Checking.State(
353+
val state = Checking.State(
354354
visited = Set.empty,
355355
path = Vector.empty,
356356
thisClass = dep.cls,
357357
fieldsInited = mutable.Set.empty,
358358
parentsInited = mutable.Set.empty,
359359
safePromoted = mutable.Set(ThisRef()(dep.cls.defTree)),
360360
dependencies = mutable.Set.empty,
361-
env = env
362-
) {
363-
override def isFieldInitialized(field: Symbol): Boolean = true
364-
}
361+
env = env,
362+
init = true
363+
)
365364

366365
val pot = Hot(dep.cls)(dep.source)
367366
val effs = pot.effectsOf(dep.symbol)(using env)
368367

369368
val errs = effs.flatMap(Checking.check(_)(using state))
370-
assert(errs.isEmpty, "unexpected errors: " + Errors.show(errs.toList))
369+
assert(errs.isEmpty, "unexpected errors: " + Errors.show(errs.toList) + " while analyzing " + dep.show)
371370

372371
state.dependencies.toList
373372
}

0 commit comments

Comments
 (0)