Skip to content

Commit 9cbfad6

Browse files
committed
Make entered and 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 aecbb4c commit 9cbfad6

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,10 @@ object Symbols {
553553

554554
/** This symbol entered into owner's scope (owner must be a class). */
555555
final def entered(implicit ctx: Context): this.type = {
556-
assert(this.owner.isClass, s"symbol ($this) entered the scope of non-class owner ${this.owner}") // !!! DEBUG
557-
this.owner.asClass.enter(this)
558-
if (this.is(Module)) this.owner.asClass.enter(this.moduleClass)
556+
if (this.owner.isClass) {
557+
this.owner.asClass.enter(this)
558+
if (this.is(Module)) this.owner.asClass.enter(this.moduleClass)
559+
}
559560
this
560561
}
561562

@@ -566,14 +567,16 @@ object Symbols {
566567
*/
567568
def enteredAfter(phase: DenotTransformer)(implicit ctx: Context): this.type =
568569
if (ctx.phaseId != phase.next.id) enteredAfter(phase)(ctx.withPhase(phase.next))
569-
else {
570-
if (this.owner.is(Package)) {
571-
denot.validFor |= InitialPeriod
572-
if (this.is(Module)) this.moduleClass.validFor |= InitialPeriod
573-
}
574-
else this.owner.asClass.ensureFreshScopeAfter(phase)
575-
assert(isPrivate || phase.changesMembers, i"$this entered in ${this.owner} at undeclared phase $phase")
576-
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
577580
}
578581

579582
/** 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
@@ -300,8 +300,9 @@ object LambdaLift {
300300
proxyMap(owner) = {
301301
for (fv <- freeValues.toList) yield {
302302
val proxyName = newName(fv)
303-
val proxy = ctx.newSymbol(owner, proxyName.asTermName, newFlags, fv.info, coord = fv.coord)
304-
if (owner.isClass) proxy.enteredAfter(thisPhase)
303+
val proxy =
304+
ctx.newSymbol(owner, proxyName.asTermName, newFlags, fv.info, coord = fv.coord)
305+
.enteredAfter(thisPhase)
305306
(fv, proxy)
306307
}
307308
}.toMap

0 commit comments

Comments
 (0)