Skip to content

Commit 9c7362b

Browse files
committed
Elide prefixes in printed types uniformly in runtime reflection
The logic that decides to print `Function`, rather than `scala.Function` did not account for the multiplicity of symbols for a given package in the JavaMirrors universe.
1 parent ca07e6c commit 9c7362b

22 files changed

+59
-56
lines changed

src/reflect/scala/reflect/internal/Symbols.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -869,10 +869,13 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
869869
/** Conditions where we omit the prefix when printing a symbol, to avoid
870870
* unpleasantries like Predef.String, $iw.$iw.Foo and <empty>.Bippy.
871871
*/
872-
final def isOmittablePrefix = /*!settings.debug.value &&*/ (
873-
UnqualifiedOwners(skipPackageObject)
874-
|| isEmptyPrefix
875-
)
872+
final def isOmittablePrefix = /*!settings.debug.value &&*/ {
873+
// scala/bug#5941 runtime reflection can have distinct symbols representing `package scala` (from different mirrors)
874+
// We check equality by FQN here to make sure we omit prefixes uniformly for all of them.
875+
def matches(sym1: Symbol, sym2: Symbol) = (sym1 eq sym2) || (sym1.hasPackageFlag && sym2.hasPackageFlag && sym1.name == sym2.name && sym1.fullNameString == sym2.fullNameString)
876+
val skipped = skipPackageObject
877+
UnqualifiedOwners.exists((sym: Symbol) => matches(sym, skipped)) || isEmptyPrefix
878+
}
876879
def isEmptyPrefix = (
877880
isEffectiveRoot // has no prefix for real, <empty> or <root>
878881
|| isAnonOrRefinementClass // has uninteresting <anon> or <refinement> prefix

test/files/jvm/manifests-new.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ x=(), t=TypeTag[Unit], k=TypeRef, s=class Unit
22
x=true, t=TypeTag[Boolean], k=TypeRef, s=class Boolean
33
x=a, t=TypeTag[Char], k=TypeRef, s=class Char
44
x=1, t=TypeTag[Int], k=TypeRef, s=class Int
5-
x=abc, t=TypeTag[java.lang.String], k=TypeRef, s=class String
5+
x=abc, t=TypeTag[String], k=TypeRef, s=class String
66
x='abc, t=TypeTag[Symbol], k=TypeRef, s=class Symbol
77

88
x=List(()), t=TypeTag[List[Unit]], k=TypeRef, s=class List
99
x=List(true), t=TypeTag[List[Boolean]], k=TypeRef, s=class List
1010
x=List(1), t=TypeTag[List[Int]], k=TypeRef, s=class List
11-
x=List(abc), t=TypeTag[List[java.lang.String]], k=TypeRef, s=class List
11+
x=List(abc), t=TypeTag[List[String]], k=TypeRef, s=class List
1212
x=List('abc), t=TypeTag[List[Symbol]], k=TypeRef, s=class List
1313

1414
x=[Z, t=TypeTag[Array[Boolean]], k=TypeRef, s=class Array
1515
x=[C, t=TypeTag[Array[Char]], k=TypeRef, s=class Array
1616
x=[I, t=TypeTag[Array[Int]], k=TypeRef, s=class Array
17-
x=[Ljava.lang.String;, t=TypeTag[Array[java.lang.String]], k=TypeRef, s=class Array
17+
x=[Ljava.lang.String;, t=TypeTag[Array[String]], k=TypeRef, s=class Array
1818
x=[Lscala.Symbol;, t=TypeTag[Array[Symbol]], k=TypeRef, s=class Array
1919

2020
x=((),()), t=TypeTag[(Unit, Unit)], k=TypeRef, s=class Tuple2
2121
x=(true,false), t=TypeTag[(Boolean, Boolean)], k=TypeRef, s=class Tuple2
2222
x=(1,2), t=TypeTag[(Int, Int)], k=TypeRef, s=class Tuple2
23-
x=(abc,xyz), t=TypeTag[(java.lang.String, java.lang.String)], k=TypeRef, s=class Tuple2
23+
x=(abc,xyz), t=TypeTag[(String, String)], k=TypeRef, s=class Tuple2
2424
x=('abc,'xyz), t=TypeTag[(Symbol, Symbol)], k=TypeRef, s=class Tuple2
2525

2626
x=Test$, t=TypeTag[Test.type], k=SingleType, s=object Test

test/files/run/abstypetags_core.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TypeTag[AnyVal]
2323
true
2424
TypeTag[AnyRef]
2525
true
26-
TypeTag[java.lang.Object]
26+
TypeTag[Object]
2727
true
2828
TypeTag[Null]
2929
true

test/files/run/exprs_serialize.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Expr[Int(2)](2)
2-
Expr[java.lang.String]({
2+
Expr[String]({
33
def foo = "hello";
44
foo.$plus("world!")
55
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
scala.List[Int]
1+
List[Int]

test/files/run/inferred-type-constructors-hou.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ warning: there were two feature warnings; re-run with -feature for details
5151
Seq[Int]
5252
Array[Int]
5353
scala.collection.AbstractSet[Int]
54-
Comparable[java.lang.String]
54+
Comparable[String]
5555
scala.collection.immutable.LinearSeq[Int]
5656
Iterable[Int]

test/files/run/inferred-type-constructors.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ warning: there were two feature warnings; re-run with -feature for details
5151
Seq[Int]
5252
Array[Int]
5353
scala.collection.AbstractSet[Int]
54-
Comparable[java.lang.String]
54+
Comparable[String]
5555
scala.collection.immutable.LinearSeq[Int]
5656
Iterable[Int]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Int
2-
java.lang.String
2+
String
33
Array[Int]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Int
2-
java.lang.String
2+
String
33
Array[Int]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
hello world = Expr[java.lang.String("hello world")]("hello world")
1+
hello world = Expr[String("hello world")]("hello world")

0 commit comments

Comments
 (0)