Skip to content

Commit 0796461

Browse files
committed
Simple case working
1 parent 9c9d4ec commit 0796461

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,16 @@ object Checking {
164164
case Promote(pot) =>
165165
pot match {
166166
case pot: ThisRef =>
167-
PromoteThis(pot, eff.source, state2.path).toErrors
168-
167+
// If we have all fields initialized, then we can promote This to hot.
168+
val classRef = state.thisClass.info.asInstanceOf[ClassInfo].appliedRef
169+
val allFieldsInited = classRef.fields.forall { denot =>
170+
val sym = denot.symbol
171+
sym.isOneOf(Flags.Lazy | Flags.Deferred) || state.fieldsInited.contains(sym)
172+
}
173+
if (allFieldsInited)
174+
Errors.empty
175+
else
176+
PromoteThis(pot, eff.source, state2.path).toErrors
169177
case _: Cold =>
170178
PromoteCold(eff.source, state2.path).toErrors
171179

0 commit comments

Comments
 (0)