Skip to content

Commit 31a90b4

Browse files
oderskyDarkDimius
authored andcommitted
Homogenize package ids and literals
The unpickled term in a package id is different from the original but the type is the same. In a literal prefer constants in the types over thsoe in the terms. With this change, we get identical typed tree output also for core/pickled.
1 parent bb5762a commit 31a90b4

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
252252
prefix ~ (" extends" provided !ofNew) ~~ parentsText ~~ bodyText
253253
}
254254

255+
def toTextPackageId(pid: Tree): Text =
256+
if (homogenizedView) toTextLocal(pid.tpe)
257+
else toTextLocal(pid)
258+
255259
var txt: Text = tree match {
256260
case id: Trees.BackquotedIdent[_] if !homogenizedView =>
257261
"`" ~ toText(id.name) ~ "`"
@@ -282,7 +286,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
282286
case TypeApply(fun, args) =>
283287
toTextLocal(fun) ~ "[" ~ toTextGlobal(args, ", ") ~ "]"
284288
case Literal(c) =>
285-
toText(c)
289+
tree.typeOpt match {
290+
case ConstantType(tc) => toText(tc)
291+
case _ => toText(c)
292+
}
286293
case New(tpt) =>
287294
"new " ~ {
288295
tpt match {
@@ -404,7 +411,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
404411
}
405412
val bodyText =
406413
if (currentPrecedence == TopLevelPrec) "\n" ~ statsText else " {" ~ statsText ~ "}"
407-
"package " ~ toTextLocal(pid) ~ bodyText
414+
"package " ~ toTextPackageId(pid) ~ bodyText
408415
case tree: Template =>
409416
toTextTemplate(tree)
410417
case Annotated(annot, arg) =>
@@ -509,7 +516,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
509516

510517
def optText[T >: Untyped](tree: List[Tree[T]])(encl: Text => Text): Text =
511518
if (tree.exists(!_.isEmpty)) encl(blockText(tree)) else ""
512-
519+
513520
override protected def polyParamName(name: TypeName): TypeName =
514521
name.unexpandedName
515522

test/dotc/tests.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ class tests extends CompilerTest {
1919
"-d", "./out/"
2020
)
2121

22+
val doEmitBytecode = List("-Ystop-before:terminal")
23+
val failedbyName = List("-Ystop-before:collectEntryPoints") // #288
24+
val failedUnderscore = List("-Ystop-before:collectEntryPoints") // #289
25+
val testPickling = List("-Xprint-types", "-Ytest-pickler", "-Ystop-after:pickler")
26+
2227
val failedOther = List("-Ystop-before:collectEntryPoints") // some non-obvious reason. need to look deeper
2328
val twice = List("#runs", "2", "-YnoDoubleBindings")
2429
val staleSymbolError: List[String] = List()
@@ -32,8 +37,8 @@ class tests extends CompilerTest {
3237
val newDir = "./tests/new/"
3338
val dotcDir = "./src/dotty/"
3439

35-
@Test def pickle_pickleOK = compileDir(posDir + "pickleOK/", "-Xprint-types" :: testPickling)
36-
@Test def pickle_pickling = compileDir(dotcDir + "tools/dotc/core/pickling", testPickling)
40+
@Test def pickle_pickleOK = compileDir(posDir + "pickleOK/", testPickling)
41+
@Test def pickle_pickling = compileDir(dotcDir + "tools/dotc/core/pickling/", testPickling)
3742

3843
@Test def pos_t2168_pat = compileFile(posDir, "t2168")
3944
@Test def pos_erasure = compileFile(posDir, "erasure")
@@ -175,6 +180,6 @@ class tests extends CompilerTest {
175180

176181
val javaDir = "./tests/pos/java-interop/"
177182
@Test def java_all = compileFiles(javaDir)
178-
183+
179184
//@Test def dotc_compilercommand = compileFile(dotcDir + "tools/dotc/config/", "CompilerCommand")
180185
}

0 commit comments

Comments
 (0)