Skip to content

Commit 67f915c

Browse files
natsukagamimichelou
authored andcommitted
Add checks for member classes
1 parent 4bdb4ea commit 67f915c

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
@@ -360,20 +360,36 @@ object Checking {
360360
// Warm[F, pot].init!, Promote(Warm[F, pot])
361361
private def checkPromoteWarm(warm: Warm, eff: Effect)(using state: State): Errors =
362362
val Warm(cls, outer) = warm
363+
val source = eff.source
363364
// Errors.empty
364365
val classRef = cls.info.asInstanceOf[ClassInfo].appliedRef
365366
// 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(_))
367+
val buffer = new mutable.ArrayBuffer[Effect]
368+
val excludedFlags = Flags.Deferred | Flags.Private | Flags.Protected
369+
370+
classRef.fields.foreach { denot =>
371+
val f = denot.symbol
372+
if !f.isOneOf(excludedFlags) && f.hasSource then
373+
buffer += Promote(FieldReturn(warm, f)(source))(source)
374+
buffer += FieldAccess(warm, f)(source)
375+
}
376+
377+
classRef.membersBasedOnFlags(Flags.Method, Flags.Deferred).foreach { denot =>
378+
val m = denot.symbol
379+
if !m.isConstructor && m.hasSource && !theEnv.canIgnoreMethod(m) then
380+
buffer += MethodCall(warm, m)(source)
381+
buffer += Promote(MethodReturn(warm, m)(source))(source)
382+
}
371383

372-
// All inner classes of classRef must be promotable.
373-
// TODO: Implement this
374-
val innerClassesErrs = Errors.empty
384+
classRef.memberClasses.foreach { denot =>
385+
val cls = denot.symbol.asClass
386+
if cls.hasSource then
387+
val potInner = Potentials.asSeenFrom(Warm(cls, ThisRef()(source))(source), warm)
388+
buffer += MethodCall(potInner, cls.primaryConstructor)(source)
389+
buffer += Promote(potInner)(source)
390+
}
375391

376-
val errs = memberErrs ++ innerClassesErrs
392+
val errs = buffer.toList.flatMap(eff => check(eff))
377393
if errs.isEmpty then {
378394
Errors.empty
379395
} else {

0 commit comments

Comments
 (0)