Skip to content

Commit 4bdb4ea

Browse files
natsukagamimichelou
authored andcommitted
WIP: Rule 2 implementation
1 parent f4a0b06 commit 4bdb4ea

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,40 @@ object Checking {
346346
}
347347
Errors.empty
348348

349+
/// Check the Promotion of a Warm object, according to "Rule 2":
350+
//
351+
// Rule 2: Promote(pot)
352+
//
353+
// for all concrete methods `m` of D
354+
// pot.m!, Promote(pot.m)
355+
//
356+
// for all concrete fields `f` of D
357+
// Promote(pot.f)
358+
//
359+
// for all inner classes `F` of D
360+
// Warm[F, pot].init!, Promote(Warm[F, pot])
361+
private def checkPromoteWarm(warm: Warm, eff: Effect)(using state: State): Errors =
362+
val Warm(cls, outer) = warm
363+
// Errors.empty
364+
val classRef = cls.info.asInstanceOf[ClassInfo].appliedRef
365+
// All members of class must be promotable.
366+
val memberErrs = classRef.allMembers.flatMap { denot =>
367+
val sym = denot.symbol
368+
val summary = warm.toPots.select(sym, warm.source, true)
369+
(summary.effs ++ summary.pots.map(Promote(_)(warm.source)).toList)
370+
}.flatMap(check(_))
371+
372+
// All inner classes of classRef must be promotable.
373+
// TODO: Implement this
374+
val innerClassesErrs = Errors.empty
375+
376+
val errs = memberErrs ++ innerClassesErrs
377+
if errs.isEmpty then {
378+
Errors.empty
379+
} else {
380+
UnsafePromotion(warm, eff.source, state.path, errs.toList).toErrors
381+
}
382+
349383
private def checkPromote(eff: Promote)(using state: State): Errors =
350384
if (state.safePromoted.contains(eff.potential)) Errors.empty
351385
else {

0 commit comments

Comments
 (0)