Skip to content

Commit 97756a7

Browse files
Merge pull request #6113 from dotty-staging/add-missing-package-prefix
Print missing package prefixes
2 parents 4e1d3d4 + c09e1a9 commit 97756a7

15 files changed

+43
-42
lines changed

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,14 @@ trait Printers
14441444

14451445
case Type.SymRef(sym, prefix) =>
14461446
prefix match {
1447-
case Types.EmptyPrefix() =>
1447+
case Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) =>
1448+
case NoPrefix() =>
1449+
if (sym.owner.flags.is(Flags.Package)) {
1450+
// TODO should these be in the prefix? These are at least `scala`, `java` and `scala.collection`.
1451+
val packagePath = sym.owner.fullName.stripPrefix("<root>").stripPrefix("<empty>").stripPrefix(".")
1452+
if (packagePath != "")
1453+
this += packagePath += "."
1454+
}
14481455
case IsType(prefix @ Type.SymRef(IsClassSymbol(_), _)) =>
14491456
printType(prefix)
14501457
this += "#"
@@ -1521,7 +1528,7 @@ trait Printers
15211528
this += highlightTypeDef(".this", color)
15221529
case Type.TypeRef(name, prefix) if name.endsWith("$") =>
15231530
prefix match {
1524-
case Types.EmptyPrefix() =>
1531+
case NoPrefix() | Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) =>
15251532
case _ =>
15261533
printTypeOrBound(prefix)
15271534
this += "."
@@ -1818,12 +1825,6 @@ trait Printers
18181825
}
18191826
}
18201827

1821-
object EmptyPrefix {
1822-
def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Boolean = tpe match {
1823-
case NoPrefix() | Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) => true
1824-
case _ => false
1825-
}
1826-
}
18271828
}
18281829

18291830
object PackageObject {

tests/pos/simpleExtractors-1.decompiled

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ object Bar {
22
def unapply(arg: scala.Any): scala.Option[scala.Any] = scala.Some.apply[scala.Any](arg)
33
}
44
object BarSeq {
5-
def unapplySeq(arg: scala.Any): scala.Option[scala.Seq[scala.Any]] = scala.Some.apply[collection.immutable.List[scala.Any]](scala.List.apply[scala.Any](arg))
5+
def unapplySeq(arg: scala.Any): scala.Option[scala.Seq[scala.Any]] = scala.Some.apply[scala.collection.immutable.List[scala.Any]](scala.List.apply[scala.Any](arg))
66
}
77
object Baz {
88
def unapply[T](arg: T): scala.Option[T] = scala.Some.apply[T](arg)
99
}
1010
object BazSeq {
11-
def unapplySeq[T](arg: T): scala.Option[scala.Seq[T]] = scala.Some.apply[collection.immutable.List[T]](scala.List.apply[T](arg))
11+
def unapplySeq[T](arg: T): scala.Option[scala.Seq[T]] = scala.Some.apply[scala.collection.immutable.List[T]](scala.List.apply[T](arg))
1212
}
1313
class Foo() {
1414
def bar(x: scala.Any): scala.Unit = x match {

tests/pos/varargs-position.decompiled

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
object varargspos {
22
def g(a: scala.Int, x: scala.Int*): scala.Int = a.+(x.length)
33
varargspos.g(1, 2, 3, 4)
4-
val xs: collection.immutable.List[scala.Int] = scala.Nil.::[scala.Int](2).::[scala.Int](1)
4+
val xs: scala.collection.immutable.List[scala.Int] = scala.Nil.::[scala.Int](2).::[scala.Int](1)
55
val a: scala.Int = 8
66
val b: scala.Int = 7
77
varargspos.g(5, varargspos.xs: _*)
88
varargspos.g(3, scala.Nil: _*)
99
varargspos.g(varargspos.a, varargspos.xs: _*)
1010
varargspos.g(varargspos.a, varargspos.b, 2, 3)
1111
varargspos.g(1)
12-
}
12+
}

tests/run-with-compiler/i3947.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
scala.Predef.classOf[lang.Object].getCanonicalName()
2+
scala.Predef.classOf[java.lang.Object].getCanonicalName()
33
java.lang.Object
44

5-
scala.Predef.classOf[lang.Object].getCanonicalName()
5+
scala.Predef.classOf[java.lang.Object].getCanonicalName()
66
java.lang.Object
77

8-
scala.Predef.classOf[lang.Object].getCanonicalName()
8+
scala.Predef.classOf[java.lang.Object].getCanonicalName()
99
java.lang.Object
1010

11-
scala.Predef.classOf[lang.Object].getCanonicalName()
11+
scala.Predef.classOf[java.lang.Object].getCanonicalName()
1212
java.lang.Object

tests/run-with-compiler/i3947c.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

2-
scala.Predef.classOf[runtime.Null].getCanonicalName()
2+
scala.Predef.classOf[scala.runtime.Null].getCanonicalName()
33
scala.runtime.Null$
44

5-
scala.Predef.classOf[runtime.Nothing].getCanonicalName()
5+
scala.Predef.classOf[scala.runtime.Nothing].getCanonicalName()
66
scala.runtime.Nothing$
77

8-
scala.Predef.classOf[lang.String].getCanonicalName()
8+
scala.Predef.classOf[java.lang.String].getCanonicalName()
99
java.lang.String

tests/run-with-compiler/i3947e.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
scala.Predef.classOf[lang.Object].getCanonicalName()
2+
scala.Predef.classOf[java.lang.Object].getCanonicalName()
33
java.lang.Object
44

55
scala.Predef.classOf[scala.Array[Foo]].getCanonicalName()

tests/run-with-compiler/i3947f.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
scala.Predef.classOf[scala.Array[lang.Object]].getCanonicalName()
2+
scala.Predef.classOf[scala.Array[java.lang.Object]].getCanonicalName()
33
java.lang.Object[]
44

5-
scala.Predef.classOf[scala.Array[lang.Object]].getCanonicalName()
5+
scala.Predef.classOf[scala.Array[java.lang.Object]].getCanonicalName()
66
java.lang.Object[]
77

8-
scala.Predef.classOf[scala.Array[lang.Object]].getCanonicalName()
8+
scala.Predef.classOf[scala.Array[java.lang.Object]].getCanonicalName()
99
java.lang.Object[]
1010

11-
scala.Predef.classOf[scala.Array[lang.Object]].getCanonicalName()
11+
scala.Predef.classOf[scala.Array[java.lang.Object]].getCanonicalName()
1212
java.lang.Object[]

tests/run-with-compiler/i5965.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
val y: collection.immutable.List[scala.Int] = scala.List.apply[scala.Int](1, 2, 3)
2+
val y: scala.collection.immutable.List[scala.Int] = scala.List.apply[scala.Int](1, 2, 3)
33

4-
(y: collection.immutable.List[scala.Int])
4+
(y: scala.collection.immutable.List[scala.Int])
55
}
66
List(1, 2, 3)
77
{
@@ -11,8 +11,8 @@ List(1, 2, 3)
1111
}
1212
Some(4)
1313
{
14-
val y: collection.immutable.Map[scala.Int, scala.Int] = scala.Predef.Map.apply[scala.Int, scala.Int](scala.Predef.ArrowAssoc[scala.Int](4).->[scala.Int](1))
14+
val y: scala.collection.immutable.Map[scala.Int, scala.Int] = scala.Predef.Map.apply[scala.Int, scala.Int](scala.Predef.ArrowAssoc[scala.Int](4).->[scala.Int](1))
1515

16-
(y: collection.immutable.Map[scala.Int, scala.Int])
16+
(y: scala.collection.immutable.Map[scala.Int, scala.Int])
1717
}
1818
Map(4 -> 1)

tests/run-with-compiler/i5965b.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
val y: collection.immutable.List[scala.Int] = scala.List.apply[scala.Int](1, 2, 3)
2+
val y: scala.collection.immutable.List[scala.Int] = scala.List.apply[scala.Int](1, 2, 3)
33

4-
(y: collection.immutable.List[scala.Int])
4+
(y: scala.collection.immutable.List[scala.Int])
55
}
66
List(1, 2, 3)
77
{
@@ -11,8 +11,8 @@ List(1, 2, 3)
1111
}
1212
Some(4)
1313
{
14-
val y: collection.immutable.Map[scala.Int, scala.Int] = scala.Predef.Map.apply[scala.Int, scala.Int](scala.Predef.ArrowAssoc[scala.Int](4).->[scala.Int](1))
14+
val y: scala.collection.immutable.Map[scala.Int, scala.Int] = scala.Predef.Map.apply[scala.Int, scala.Int](scala.Predef.ArrowAssoc[scala.Int](4).->[scala.Int](1))
1515

16-
(y: collection.immutable.Map[scala.Int, scala.Int])
16+
(y: scala.collection.immutable.Map[scala.Int, scala.Int])
1717
}
1818
Map(4 -> 1)

tests/run-with-compiler/quote-owners-2.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
3
22
{
33
def ff: scala.Int = {
4-
val a: immutable.List[scala.Int] = {
4+
val a: scala.collection.immutable.List[scala.Int] = {
55
type T = scala.List[scala.Int]
66
val b: T = scala.Nil.::[scala.Int](3)
77

8-
(b: collection.immutable.List[scala.Int])
8+
(b: scala.collection.immutable.List[scala.Int])
99
}
1010

1111
(a.head: scala.Int)

0 commit comments

Comments
 (0)