Skip to content

Commit 010f47e

Browse files
committed
Use symbols to detect root and empty package
1 parent 95c52a5 commit 010f47e

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ trait Printers
15181518
case Type.IsTypeRef(tpe) =>
15191519
val sym = tpe.typeSymbol
15201520
tpe.qualifier match {
1521-
case Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) =>
1521+
case Type.ThisType(tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass =>
15221522
case NoPrefix() =>
15231523
if (sym.owner.flags.is(Flags.Package)) {
15241524
// TODO should these be in the prefix? These are at least `scala`, `java` and `scala.collection`.
@@ -1542,7 +1542,9 @@ trait Printers
15421542

15431543
case Type.TermRef(prefix, name) =>
15441544
prefix match {
1545-
case NoPrefix() | Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) =>
1545+
case NoPrefix() =>
1546+
this += highlightTypeDef(name)
1547+
case Type.ThisType(tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass =>
15461548
this += highlightTypeDef(name)
15471549
case _ =>
15481550
printTypeOrBound(prefix)
@@ -1597,7 +1599,8 @@ trait Printers
15971599
this += highlightTypeDef(".this")
15981600
case Type.TypeRef(prefix, name) if name.endsWith("$") =>
15991601
prefix match {
1600-
case NoPrefix() | Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) =>
1602+
case NoPrefix() =>
1603+
case Type.ThisType(tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass =>
16011604
case _ =>
16021605
printTypeOrBound(prefix)
16031606
this += "."
@@ -1903,20 +1906,6 @@ trait Printers
19031906
}
19041907
}
19051908

1906-
object RootPackage {
1907-
def unapply(tpe: TypeOrBounds) given (ctx: Context): Boolean = tpe match {
1908-
case Type.IsTypeRef(tpe) => tpe.typeSymbol.fullName == "<root>" // TODO use Symbol.==
1909-
case _ => false
1910-
}
1911-
}
1912-
1913-
object EmptyPackage {
1914-
def unapply(tpe: TypeOrBounds) given (ctx: Context): Boolean = tpe match {
1915-
case Type.IsTypeRef(tpe) => tpe.typeSymbol.fullName == "<empty>"
1916-
case _ => false
1917-
}
1918-
}
1919-
19201909
}
19211910

19221911
object PackageObject {

0 commit comments

Comments
 (0)