Skip to content

Commit 2181000

Browse files
committed
Fix handling of empty package and ASTs name
1 parent 099d925 commit 2181000

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

compiler/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object DottyUnpickler {
1616
class BadSignature(msg: String) extends RuntimeException(msg)
1717

1818
class TreeSectionUnpickler(posUnpickler: Option[PositionUnpickler], commentUnpickler: Option[CommentUnpickler])
19-
extends SectionUnpickler[TreeUnpickler]("ASTs") {
19+
extends SectionUnpickler[TreeUnpickler](TreePickler.sectionName) {
2020
def unpickle(reader: TastyReader, nameAtRef: NameTable): TreeUnpickler =
2121
new TreeUnpickler(reader, nameAtRef, posUnpickler, commentUnpickler, Seq.empty)
2222
}

compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
3434
unpickle(new CommentSectionUnpickler)
3535
}
3636

37-
class TreeSectionUnpickler extends SectionUnpickler[Unit]("ASTs") {
37+
class TreeSectionUnpickler extends SectionUnpickler[Unit](TreePickler.sectionName) {
3838
import TastyFormat._
3939
def unpickle(reader: TastyReader, tastyName: NameTable): Unit = {
4040
import reader._

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import printing.Texts._
1717

1818
object TreePickler {
1919

20+
val sectionName = "ASTs"
21+
2022
case class Hole(idx: Int, args: List[tpd.Tree]) extends tpd.Tree {
2123
override def fallbackToText(printer: Printer): Text =
2224
s"[[$idx|" ~~ printer.toTextGlobal(args, ", ") ~~ "]]"
@@ -25,7 +27,7 @@ object TreePickler {
2527

2628
class TreePickler(pickler: TastyPickler) {
2729
val buf: TreeBuffer = new TreeBuffer
28-
pickler.newSection("ASTs", buf)
30+
pickler.newSection(TreePickler.sectionName, buf)
2931
import TreePickler._
3032
import buf._
3133
import pickler.nameBuffer.nameIndex

compiler/src/dotty/tools/dotc/fromtasty/TastyFileUtil.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import dotty.tools.dotc.core.Contexts.Context
66
import dotty.tools.dotc.core.NameKinds
77
import dotty.tools.dotc.core.Names.SimpleName
88
import dotty.tools.dotc.core.StdNames.nme
9-
import dotty.tools.dotc.core.tasty.TastyUnpickler
9+
import dotty.tools.dotc.core.tasty.{TastyUnpickler, TreePickler}
1010

1111
object TastyFileUtil {
1212

@@ -25,14 +25,16 @@ object TastyFileUtil {
2525
val bytes = Files.readAllBytes(path)
2626
val unpickler: TastyUnpickler = new TastyUnpickler(bytes)
2727
val className =
28-
unpickler.nameAtRef.contents.iterator.takeWhile {
28+
unpickler.nameAtRef.contents.iterator.dropWhile {
29+
name => name.toString == TreePickler.sectionName || name == nme.EMPTY_PACKAGE
30+
}.takeWhile {
2931
case name: SimpleName => name != nme.CONSTRUCTOR
3032
case name => !name.is(NameKinds.ModuleClassName)
3133
}.collect {
3234
case name: SimpleName => name.toString
33-
}.drop(1).toList
34-
35-
val classpath = path.toString.replace(className.mkString("", "/", ".tasty"), "")
35+
}.toList
36+
val classInPath = className.mkString("", "/", ".tasty")
37+
val classpath = path.toString.replace(classInPath, "")
3638
(classpath, className.mkString("."))
3739
}
3840

0 commit comments

Comments
 (0)