Skip to content

Commit 0bbafb2

Browse files
committed
Add checks for member classes
1 parent 0fb4a4b commit 0bbafb2

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,20 +289,36 @@ object Checking {
289289
// Warm[F, pot].init!, Promote(Warm[F, pot])
290290
private def checkPromoteWarm(warm: Warm, eff: Effect)(using state: State): Errors =
291291
val Warm(cls, outer) = warm
292+
val source = eff.source
292293
// Errors.empty
293294
val classRef = cls.info.asInstanceOf[ClassInfo].appliedRef
294295
// All members of class must be promotable.
295-
val memberErrs = classRef.allMembers.flatMap { denot =>
296-
val sym = denot.symbol
297-
val summary = warm.toPots.select(sym, warm.source, true)
298-
(summary.effs ++ summary.pots.map(Promote(_)(warm.source)).toList)
299-
}.flatMap(check(_))
296+
val buffer = new mutable.ArrayBuffer[Effect]
297+
val excludedFlags = Flags.Deferred | Flags.Private | Flags.Protected
298+
299+
classRef.fields.foreach { denot =>
300+
val f = denot.symbol
301+
if !f.isOneOf(excludedFlags) && f.hasSource then
302+
buffer += Promote(FieldReturn(warm, f)(source))(source)
303+
buffer += FieldAccess(warm, f)(source)
304+
}
305+
306+
classRef.membersBasedOnFlags(Flags.Method, Flags.Deferred).foreach { denot =>
307+
val m = denot.symbol
308+
if !m.isConstructor && m.hasSource && !theEnv.canIgnoreMethod(m) then
309+
buffer += MethodCall(warm, m)(source)
310+
buffer += Promote(MethodReturn(warm, m)(source))(source)
311+
}
300312

301-
// All inner classes of classRef must be promotable.
302-
// TODO: Implement this
303-
val innerClassesErrs = Errors.empty
313+
classRef.memberClasses.foreach { denot =>
314+
val cls = denot.symbol.asClass
315+
if cls.hasSource then
316+
val potInner = Potentials.asSeenFrom(Warm(cls, ThisRef()(source))(source), warm)
317+
buffer += MethodCall(potInner, cls.primaryConstructor)(source)
318+
buffer += Promote(potInner)(source)
319+
}
304320

305-
val errs = memberErrs ++ innerClassesErrs
321+
val errs = buffer.toList.flatMap(eff => check(eff))
306322
if errs.isEmpty then {
307323
Errors.empty
308324
} else {

0 commit comments

Comments
 (0)