Skip to content

Commit 6170bce

Browse files
committed
Properly unpickle Scala 2 refinements
They're pickled with a class symbol, but we unpickled them as a type aliases, which meant that the logic in REFINEDtpe wasn't able to substitute `this` references correctly (there was even a comment expressing puzzlement about this). Instead, unpickle them as classes (TODO: add some logic in TreeChecker to make sure these symbols are never referenced anywhere).
1 parent b40014a commit 6170bce

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed
Submodule minitest updated 37 files

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,6 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
532532
else if (isModuleClassRoot)
533533
completeRoot(
534534
moduleClassRoot, rootClassUnpickler(start, moduleClassRoot.symbol, moduleClassRoot.sourceModule, infoRef), privateWithin)
535-
else if (name == tpnme.REFINE_CLASS)
536-
// create a type alias instead
537-
ctx.newSymbol(owner, name, flags, localMemberUnpickler, privateWithin, coord = start)
538535
else {
539536
def completer(cls: Symbol) = {
540537
val unpickler = new ClassUnpickler(infoRef) withDecls symScope(cls)
@@ -580,7 +577,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
580577
val tp = at(inforef, () => readType()(ctx))
581578

582579
denot match {
583-
case denot: ClassDenotation =>
580+
case denot: ClassDenotation if !isRefinementClass(denot.symbol) =>
584581
val selfInfo = if (atEnd) NoType else readTypeRef()
585582
setClassInfo(denot, tp, fromScala2 = true, selfInfo)
586583
case denot =>
@@ -773,19 +770,17 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
773770
case TYPEBOUNDStpe =>
774771
TypeBounds(readTypeRef(), readTypeRef())
775772
case REFINEDtpe =>
776-
val clazz = readSymbolRef()
773+
val clazz = readSymbolRef().asClass
777774
val decls = symScope(clazz)
778775
symScopes(clazz) = EmptyScope // prevent further additions
779776
val parents = until(end, () => readTypeRef())
780777
val parent = parents.reduceLeft(AndType(_, _))
781778
if (decls.isEmpty) parent
782779
else {
783-
def subst(info: Type, rt: RecType) =
784-
if (clazz.isClass) info.substThis(clazz.asClass, rt.recThis)
785-
else info // turns out some symbols read into `clazz` are not classes, not sure why this is the case.
780+
def subst(info: Type, rt: RecType) = info.substThis(clazz.asClass, rt.recThis)
786781
def addRefinement(tp: Type, sym: Symbol) = RefinedType(tp, sym.name, sym.info)
787782
val refined = decls.toList.foldLeft(parent)(addRefinement)
788-
RecType.closeOver(rt => subst(refined, rt))
783+
RecType.closeOver(rt => refined.substThis(clazz, rt.recThis))
789784
}
790785
case CLASSINFOtpe =>
791786
val clazz = readSymbolRef()

0 commit comments

Comments
 (0)