Skip to content

Commit deaa0d8

Browse files
committed
Package denotations are never transformed
Packages should always have a single denotation, which is invariant for all transformations. Package members should always be entered in the first phase, and should never be entered after a given phase. This reflects the fact that package members correspond to classfiles. Once you create a classfile, it stays around and is available from the start of the next run. Also, we need to prevent multiple denotation versions of packages from hanging on to stale symbols. It would not be enough to replace a package member by a newly compiled one; if packages had multiple denotations we'd have to do this for all of them.
1 parent ab8ee53 commit deaa0d8

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,9 @@ object Denotations {
553553
startPid = cur.validFor.firstPhaseId
554554
else {
555555
next match {
556-
case next: ClassDenotation => next.resetFlag(Frozen)
556+
case next: ClassDenotation =>
557+
assert(!next.is(Package), s"illegal transfomation of package denotation by transformer ${ctx.withPhase(transformer).phase}")
558+
next.resetFlag(Frozen)
557559
case _ =>
558560
}
559561
next.nextInRun = cur.nextInRun

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,11 @@ object Symbols {
382382
*/
383383
def enteredAfter(phase: DenotTransformer)(implicit ctx: Context): this.type = {
384384
val nextCtx = ctx.withPhase(phase.next)
385-
this.owner.asClass.ensureFreshScopeAfter(phase)(nextCtx)
385+
if (this.owner.is(Package)) {
386+
denot.validFor |= InitialPeriod
387+
if (this is Module) this.moduleClass.validFor |= InitialPeriod
388+
}
389+
else this.owner.asClass.ensureFreshScopeAfter(phase)(nextCtx)
386390
entered(nextCtx)
387391
}
388392

src/dotty/tools/dotc/core/transform/Erasure.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,15 @@ class Erasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wildcard
145145
case tp: PolyType =>
146146
this(tp.resultType)
147147
case tp @ ClassInfo(pre, cls, classParents, decls, _) =>
148-
def eraseTypeRef(p: TypeRef) = this(p).asInstanceOf[TypeRef]
149-
val parents: List[TypeRef] =
150-
if ((cls eq defn.ObjectClass) || cls.isPrimitiveValueClass) Nil
151-
else if (cls eq defn.ArrayClass) defn.ObjectClass.typeRef :: Nil
152-
else removeLaterObjects(classParents.mapConserve(eraseTypeRef))
153-
tp.derivedClassInfo(this(pre), parents, decls, this(tp.selfType))
148+
if (cls is Package) tp
149+
else {
150+
def eraseTypeRef(p: TypeRef) = this(p).asInstanceOf[TypeRef]
151+
val parents: List[TypeRef] =
152+
if ((cls eq defn.ObjectClass) || cls.isPrimitiveValueClass) Nil
153+
else if (cls eq defn.ArrayClass) defn.ObjectClass.typeRef :: Nil
154+
else removeLaterObjects(classParents.mapConserve(eraseTypeRef))
155+
tp.derivedClassInfo(this(pre), parents, decls, this(tp.selfType))
156+
}
154157
case NoType | NoPrefix | ErrorType =>
155158
tp
156159
case tp: WildcardType if wildcardOK =>

src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
109109
return (toTextLocal(tycon) ~ "[" ~ Text(args map argText, ", ") ~ "]").close
110110
}
111111
case tp: TypeRef =>
112-
if ((tp.symbol is TypeParam | TypeArgument | ExpandedName) && !ctx.phase.erasedTypes && !tp.symbol.isCompleting) {
112+
val hideType = tp.symbol is TypeParam | TypeArgument | ExpandedName
113+
if (hideType && !ctx.phase.erasedTypes && !tp.symbol.isCompleting) {
113114
tp.info match {
114115
case TypeAlias(hi) => return toText(hi)
115116
case _ => if (tp.prefix.isInstanceOf[ThisType]) return nameString(tp.symbol)

0 commit comments

Comments
 (0)