Skip to content

Commit 1adc173

Browse files
committed
Add expand logic to canDirectlyPromote
1 parent ea9db4b commit 1adc173

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ object Checking {
270270
/// A potential can be (currently) directly promoted if and only if:
271271
/// - `pot == this` and all fields of this are initialized, or
272272
/// - `pot == Warm(C, outer)` where `outer` can be directly promoted.
273-
private def canDirectlyPromote(pot: Potential)(using state: State): Boolean =
273+
private def canDirectlyPromote(pot: Potential)(using state: State): Boolean = trace("checking direct promotion of " + pot.show, init) {
274274
if (state.safePromoted.contains(pot)) true
275275
else pot match {
276276
case pot: ThisRef =>
@@ -282,8 +282,13 @@ object Checking {
282282
}
283283
case Warm(cls, outer) =>
284284
canDirectlyPromote(outer)
285-
case _ => false
285+
case _ =>
286+
val summary = expand(pot)
287+
if (!summary.effs.isEmpty)
288+
false // max depth of expansion reached
289+
else summary.pots.forall(canDirectlyPromote)
286290
}
291+
}
287292

288293
/// Check the Promotion of a Warm object, according to "Rule 2":
289294
//

0 commit comments

Comments
 (0)