Skip to content

Commit 8dd26db

Browse files
committed
Make enteredAfter also work for term members
Restricting `entered` and `enteredAfter` to class members is more a trap to fall into than a helpful check.
1 parent e8c5fbe commit 8dd26db

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -567,14 +567,16 @@ object Symbols {
567567
*/
568568
def enteredAfter(phase: DenotTransformer)(implicit ctx: Context): this.type =
569569
if (ctx.phaseId != phase.next.id) enteredAfter(phase)(ctx.withPhase(phase.next))
570-
else {
571-
if (this.owner.is(Package)) {
572-
denot.validFor |= InitialPeriod
573-
if (this.is(Module)) this.moduleClass.validFor |= InitialPeriod
574-
}
575-
else this.owner.asClass.ensureFreshScopeAfter(phase)
576-
assert(isPrivate || phase.changesMembers, i"$this entered in ${this.owner} at undeclared phase $phase")
577-
entered
570+
else this.owner match {
571+
case owner: ClassSymbol =>
572+
if (owner.is(Package)) {
573+
denot.validFor |= InitialPeriod
574+
if (this.is(Module)) this.moduleClass.validFor |= InitialPeriod
575+
}
576+
else owner.ensureFreshScopeAfter(phase)
577+
assert(isPrivate || phase.changesMembers, i"$this entered in $owner at undeclared phase $phase")
578+
entered
579+
case _ => this
578580
}
579581

580582
/** Remove symbol from scope of owning class */

compiler/src/dotty/tools/dotc/transform/CacheAliasImplicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CacheAliasImplicits extends MiniPhase with IdentityDenotTransformer { this
8282
val cacheFlags = if (ctx.owner.isClass) Private | Local | Mutable else Mutable
8383
val cacheSym =
8484
ctx.newSymbol(ctx.owner, CacheName(tree.name), cacheFlags, rhsType, coord = sym.coord)
85-
if (ctx.owner.isClass) cacheSym.enteredAfter(thisPhase)
85+
.enteredAfter(thisPhase)
8686
val cacheDef = ValDef(cacheSym, tpd.defaultValue(rhsType))
8787
val cachingDef = cpy.DefDef(tree)(rhs =
8888
Block(

compiler/src/dotty/tools/dotc/transform/HoistSuperArgs.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ class HoistSuperArgs extends MiniPhase with IdentityDenotTransformer { thisPhase
9191
val argTypeWrtConstr = argType.subst(origParams, allParamRefs(constr.info))
9292
// argType with references to paramRefs of the primary constructor instead of
9393
// local parameter accessors
94-
val meth = ctx.newSymbol(
94+
ctx.newSymbol(
9595
owner = methOwner,
9696
name = SuperArgName.fresh(cls.name.toTermName),
9797
flags = Synthetic | Private | Method | staticFlag,
9898
info = replaceResult(constr.info, argTypeWrtConstr),
99-
coord = constr.coord)
100-
if (methOwner.isClass) meth.enteredAfter(thisPhase) else meth
99+
coord = constr.coord
100+
).enteredAfter(thisPhase)
101101
}
102102

103103
/** Type of a reference implies that it needs to be hoisted */

compiler/src/dotty/tools/dotc/transform/LambdaLift.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,9 @@ object LambdaLift {
298298
proxyMap(owner) = {
299299
for (fv <- freeValues.toList) yield {
300300
val proxyName = newName(fv)
301-
val proxy = ctx.newSymbol(owner, proxyName.asTermName, newFlags, fv.info, coord = fv.coord)
302-
if (owner.isClass) proxy.enteredAfter(thisPhase)
301+
val proxy =
302+
ctx.newSymbol(owner, proxyName.asTermName, newFlags, fv.info, coord = fv.coord)
303+
.enteredAfter(thisPhase)
303304
(fv, proxy)
304305
}
305306
}.toMap

0 commit comments

Comments
 (0)