Skip to content

Commit 9620f9d

Browse files
committed
Add expand logic to canDirectlyPromote
1 parent 0bbafb2 commit 9620f9d

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
@@ -260,7 +260,7 @@ object Checking {
260260
/// A potential can be (currently) directly promoted if and only if:
261261
/// - `pot == this` and all fields of this are initialized, or
262262
/// - `pot == Warm(C, outer)` where `outer` can be directly promoted.
263-
private def canDirectlyPromote(pot: Potential)(using state: State): Boolean =
263+
private def canDirectlyPromote(pot: Potential)(using state: State): Boolean = trace("checking direct promotion of " + pot.show, init) {
264264
if (state.safePromoted.contains(pot)) true
265265
else pot match {
266266
case pot: ThisRef =>
@@ -272,8 +272,13 @@ object Checking {
272272
}
273273
case Warm(cls, outer) =>
274274
canDirectlyPromote(outer)
275-
case _ => false
275+
case _ =>
276+
val summary = expand(pot)
277+
if (!summary.effs.isEmpty)
278+
false // max depth of expansion reached
279+
else summary.pots.forall(canDirectlyPromote)
276280
}
281+
}
277282

278283
/// Check the Promotion of a Warm object, according to "Rule 2":
279284
//

0 commit comments

Comments
 (0)