Skip to content

Commit 1d56a54

Browse files
committed
Unpickle Imports
Was missing before. Needed a tweak in PlainPrinter for printing import symbol references (their denotation is not current after pickling, so they would have printed differently after and before pickling).
1 parent a884556 commit 1d56a54

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,10 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
657657
}
658658

659659
def readIndexedStat(exprOwner: Symbol)(implicit ctx: Context): Tree = nextByte match {
660-
case TYPEDEF | VALDEF | DEFDEF | IMPORT =>
660+
case TYPEDEF | VALDEF | DEFDEF =>
661661
readIndexedDef()
662662
case IMPORT =>
663-
???
663+
readImport()
664664
case PACKAGE =>
665665
val start = currentAddr
666666
processPackage { (pid, end) => implicit ctx =>
@@ -669,6 +669,24 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
669669
case _ =>
670670
readTerm()(ctx.withOwner(exprOwner))
671671
}
672+
673+
def readImport()(implicit ctx: Context): Tree = {
674+
readByte()
675+
readEnd()
676+
val expr = readTerm()
677+
def readSelectors(): List[untpd.Tree] = nextByte match {
678+
case RENAMED =>
679+
readByte()
680+
readEnd()
681+
untpd.Pair(untpd.Ident(readName()), untpd.Ident(readName())) :: readSelectors()
682+
case IMPORTED =>
683+
readByte()
684+
untpd.Ident(readName()) :: readSelectors()
685+
case _ =>
686+
Nil
687+
}
688+
Import(expr, readSelectors())
689+
}
672690

673691
def readIndexedStats(exprOwner: Symbol, end: Addr)(implicit ctx: Context): List[Tree] =
674692
until(end)(readIndexedStat(exprOwner))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
109109
homogenize(tp) match {
110110
case tp: TypeType =>
111111
toTextRHS(tp)
112-
case tp: TermRef if !tp.denotationIsCurrent || tp.symbol.is(Module) =>
112+
case tp: TermRef if !tp.denotationIsCurrent || tp.symbol.is(Module) || tp.symbol.name.isImportName =>
113113
toTextRef(tp) ~ ".type"
114114
case tp: TermRef if tp.denot.isOverloaded =>
115115
"<overloaded " ~ toTextRef(tp) ~ ">"

tests/new/test.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait T {
2+
object O
3+
}
4+
5+
class C extends T
6+
7+
object Test {
8+
9+
val c = new C
10+
c.O
11+
12+
}

0 commit comments

Comments
 (0)