Skip to content

Commit be7d231

Browse files
committed
Fix Scala2 unpickler's handling of package references
1 parent 08eea86 commit be7d231

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,15 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
690690
} else tp1
691691
}
692692

693+
/** Read type ref, mapping a TypeRef to a package to the package's ThisType
694+
* Packae references should be TermRefs or ThisTypes but it was observed that
695+
* nsc sometimes pickles them as TypeRefs instead.
696+
*/
697+
private def readPrefix()(implicit ctx: Context): Type = readTypeRef() match {
698+
case pre: TypeRef if pre.symbol.is(Package) => pre.symbol.thisType
699+
case pre => pre
700+
}
701+
693702
/** Read a type
694703
*
695704
* @param forceProperType is used to ease the transition to NullaryMethodTypes (commentmarker: NMT_TRANSITION)
@@ -707,7 +716,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
707716
case THIStpe =>
708717
readSymbolRef().thisType
709718
case SINGLEtpe =>
710-
val pre = readTypeRef()
719+
val pre = readPrefix()
711720
val sym = readDisambiguatedSymbolRef(_.info.isParameterless)
712721
pre.select(sym)
713722
case SUPERtpe =>
@@ -717,7 +726,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
717726
case CONSTANTtpe =>
718727
ConstantType(readConstantRef())
719728
case TYPEREFtpe =>
720-
var pre = readTypeRef()
729+
var pre = readPrefix()
721730
val sym = readSymbolRef()
722731
pre match {
723732
case thispre: ThisType =>

0 commit comments

Comments
 (0)