Skip to content

Commit ea9db4b

Browse files
committed
Add checks for member classes
1 parent d38cc11 commit ea9db4b

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
@@ -299,20 +299,36 @@ object Checking {
299299
// Warm[F, pot].init!, Promote(Warm[F, pot])
300300
private def checkPromoteWarm(warm: Warm, eff: Effect)(using state: State): Errors =
301301
val Warm(cls, outer) = warm
302+
val source = eff.source
302303
// Errors.empty
303304
val classRef = cls.info.asInstanceOf[ClassInfo].appliedRef
304305
// All members of class must be promotable.
305-
val memberErrs = classRef.allMembers.flatMap { denot =>
306-
val sym = denot.symbol
307-
val summary = warm.toPots.select(sym, warm.source, true)
308-
(summary.effs ++ summary.pots.map(Promote(_)(warm.source)).toList)
309-
}.flatMap(check(_))
306+
val buffer = new mutable.ArrayBuffer[Effect]
307+
val excludedFlags = Flags.Deferred | Flags.Private | Flags.Protected
308+
309+
classRef.fields.foreach { denot =>
310+
val f = denot.symbol
311+
if !f.isOneOf(excludedFlags) && f.hasSource then
312+
buffer += Promote(FieldReturn(warm, f)(source))(source)
313+
buffer += FieldAccess(warm, f)(source)
314+
}
315+
316+
classRef.membersBasedOnFlags(Flags.Method, Flags.Deferred).foreach { denot =>
317+
val m = denot.symbol
318+
if !m.isConstructor && m.hasSource && !theEnv.canIgnoreMethod(m) then
319+
buffer += MethodCall(warm, m)(source)
320+
buffer += Promote(MethodReturn(warm, m)(source))(source)
321+
}
310322

311-
// All inner classes of classRef must be promotable.
312-
// TODO: Implement this
313-
val innerClassesErrs = Errors.empty
323+
classRef.memberClasses.foreach { denot =>
324+
val cls = denot.symbol.asClass
325+
if cls.hasSource then
326+
val potInner = Potentials.asSeenFrom(Warm(cls, ThisRef()(source))(source), warm)
327+
buffer += MethodCall(potInner, cls.primaryConstructor)(source)
328+
buffer += Promote(potInner)(source)
329+
}
314330

315-
val errs = memberErrs ++ innerClassesErrs
331+
val errs = buffer.toList.flatMap(eff => check(eff))
316332
if errs.isEmpty then {
317333
Errors.empty
318334
} else {

0 commit comments

Comments
 (0)