Skip to content

Commit 20113f4

Browse files
dwijnandKordyjan
authored andcommitted
Omit more prefixes in non-package module printing
When we pretty-print a type in a module class, we end up printing the module class's symbol. For instance in a reduction failure of Tuple.Union, we end up printing Tuple.Fold, with Tuple being an internal (ThisType) reference to the Tuple module class. I tweaked the logic in fullNameString so that we omit more prefixes, if the module is non-package (and make it consistent across -Ytest-pickler). The package part is important, because we want to continue to get "import scala.concurrent.duration..." instead of "import concurrent.duration..". [Cherry-picked fbb08f7]
1 parent 364f627 commit 20113f4

File tree

7 files changed

+36
-12
lines changed

7 files changed

+36
-12
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
9292
nameString(if (ctx.property(XprintMode).isEmpty) sym.initial.name else sym.name)
9393

9494
override def fullNameString(sym: Symbol): String =
95-
if !sym.exists || isEmptyPrefix(sym.effectiveOwner) then nameString(sym)
95+
if !sym.exists
96+
|| isEmptyPrefix(sym.effectiveOwner)
97+
|| !homogenizedView && !sym.is(Package) && isOmittablePrefix(sym.effectiveOwner)
98+
then nameString(sym)
9699
else super.fullNameString(sym)
97100

98101
override protected def fullNameOwner(sym: Symbol): Symbol = {

language-server/test/dotty/tools/languageserver/CompletionTest.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ class CompletionTest {
3232

3333
@Test def completionFromScalaPackage: Unit = {
3434
code"class Foo { val foo: Conv${m1} }"
35-
.completion(("Conversion", Class, "scala.Conversion"))
35+
.completion(("Conversion", Class, "Conversion"))
3636
}
3737

3838
@Test def completionFromScalaPackageObject: Unit = {
3939
code"class Foo { val foo: BigD${m1} }"
4040
.completion(
41-
("BigDecimal", Field, "scala.BigDecimal"),
41+
("BigDecimal", Field, "BigDecimal"),
4242
("BigDecimal", Method, "=> math.BigDecimal.type"),
4343
)
4444
}
@@ -47,14 +47,14 @@ class CompletionTest {
4747
code"class Foo { val foo: IArr${m1} }"
4848
.completion(
4949
("IArray", Module, "IArray"),
50-
("IArray", Field, "scala.IArray"),
50+
("IArray", Field, "IArray"),
5151
)
5252
}
5353

5454
@Test def completionFromJavaDefaults: Unit = {
5555
code"class Foo { val foo: Runn${m1} }"
5656
.completion(
57-
("Runnable", Class, "java.lang.Runnable"),
57+
("Runnable", Class, "Runnable"),
5858
("Runnable", Module, "Runnable"),
5959
)
6060
}
@@ -971,7 +971,7 @@ class CompletionTest {
971971
("implicitNotFound", Module, "scala.annotation.implicitNotFound"),
972972
)
973973
.completion(m2,
974-
("main", Class, "scala.main"),
974+
("main", Class, "main"),
975975
("main", Module, "main"),
976976
)
977977

tests/neg-custom-args/captures/cc-this2.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
-- Error: tests/neg-custom-args/captures/cc-this2/D_2.scala:2:6 --------------------------------------------------------
33
2 |class D extends C: // error
44
|^
5-
|reference (scala.caps.cap : Any) is not included in allowed capture set {} of pure base class class C
5+
|reference (caps.cap : Any) is not included in allowed capture set {} of pure base class class C
66
3 | this: D^ =>

tests/neg-custom-args/captures/exception-definitions.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Error: tests/neg-custom-args/captures/exception-definitions.scala:2:6 -----------------------------------------------
22
2 |class Err extends Exception: // error
33
|^
4-
|reference (scala.caps.cap : Any) is not included in allowed capture set {} of pure base class class Throwable
4+
|reference (caps.cap : Any) is not included in allowed capture set {} of pure base class class Throwable
55
3 | self: Err^ =>
66
-- Error: tests/neg-custom-args/captures/exception-definitions.scala:10:6 ----------------------------------------------
77
10 |class Err4(c: Any^) extends AnyVal // error

tests/neg/print-tuple-union.check

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- [E007] Type Mismatch Error: tests/neg/print-tuple-union.scala:3:23 --------------------------------------------------
2+
3 | def bar[B]: Int = foo[B] // error
3+
| ^^^^^^
4+
| Found: Tuple.Union[B]
5+
| Required: Int
6+
|
7+
| Note: a match type could not be fully reduced:
8+
|
9+
| trying to reduce Tuple.Union[B]
10+
| trying to reduce Tuple.Fold[B, Nothing, [x, y] =>> x | y]
11+
| failed since selector B
12+
| does not match case EmptyTuple => Nothing
13+
| and cannot be shown to be disjoint from it either.
14+
| Therefore, reduction cannot advance to the remaining case
15+
|
16+
| case h *: t => h | Tuple.Fold[t, Nothing, [x, y] =>> x | y]
17+
|
18+
| longer explanation available when compiling with `-explain`

tests/neg/print-tuple-union.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait Test:
2+
def foo[A]: Tuple.Union[A]
3+
def bar[B]: Int = foo[B] // error

tests/printing/transformed/lazy-vals-new.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ package <empty> {
2323
lazy def x(): Int =
2424
{
2525
val result: Object = A.x$lzy1
26-
if result.isInstanceOf[Int] then scala.Int.unbox(result) else
27-
if result.eq(scala.runtime.LazyVals.NullValue) then
28-
scala.Int.unbox(null) else scala.Int.unbox(A.x$lzyINIT1())
26+
if result.isInstanceOf[Int] then Int.unbox(result) else
27+
if result.eq(scala.runtime.LazyVals.NullValue) then Int.unbox(null)
28+
else Int.unbox(A.x$lzyINIT1())
2929
}
3030
private def x$lzyINIT1(): Object =
3131
while <empty> do
@@ -41,7 +41,7 @@ package <empty> {
4141
var resultNullable: Object = null
4242
try
4343
{
44-
resultNullable = scala.Int.box(2)
44+
resultNullable = Int.box(2)
4545
if resultNullable.eq(null) then
4646
result = scala.runtime.LazyVals.NullValue else
4747
result = resultNullable

0 commit comments

Comments
 (0)