Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit more prefixes in non-package module printing #17758

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
nameString(if (ctx.property(XprintMode).isEmpty) sym.initial.name else sym.name)

override def fullNameString(sym: Symbol): String =
if !sym.exists || isEmptyPrefix(sym.effectiveOwner) then nameString(sym)
if !sym.exists
|| isEmptyPrefix(sym.effectiveOwner)
|| !homogenizedView && !sym.is(Package) && isOmittablePrefix(sym.effectiveOwner)
then nameString(sym)
else super.fullNameString(sym)

override protected def fullNameOwner(sym: Symbol): Symbol = {
Expand All @@ -106,6 +109,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
if (tp.cls.isAnonymousClass) keywordStr("this")
if (tp.cls.is(ModuleClass)) fullNameString(tp.cls.sourceModule)
else super.toTextRef(tp)
case tp: TermRef if !printDebug =>
if tp.symbol.is(Package) then fullNameString(tp.symbol)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused a bit of regression in metals since we are no longer able to omit a package when printing : scalameta/metals#5327

I wonder if you could do a bit more full proof mechanism here so that we always correctly skip prefixes in both metals and compiler 🤔 It's influenced by the imports within metals.

else super.toTextRef(tp)
case _ =>
super.toTextRef(tp)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/test-resources/repl-macros/i15104c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
scala> import scala.quoted._
scala> def macroImpl(using Quotes) = Expr(1)
def macroImpl(using x$1: quoted.Quotes): quoted.Expr[Int]
def macroImpl(using x$1: scala.quoted.Quotes): scala.quoted.Expr[Int]
scala> inline def foo = ${ macroImpl }
def foo: Int
scala> foo
Expand Down
3 changes: 2 additions & 1 deletion compiler/test-resources/repl-macros/i5551
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
scala> import scala.quoted._
scala> def assertImpl(expr: Expr[Boolean])(using q: Quotes) = '{ if !($expr) then throw new AssertionError("failed assertion")}
def assertImpl
(expr: quoted.Expr[Boolean])(using q: quoted.Quotes): scala.quoted.Expr[Unit]
(expr: scala.quoted.Expr[Boolean])
(using q: scala.quoted.Quotes): scala.quoted.Expr[Unit]
scala> inline def assert(expr: => Boolean): Unit = ${ assertImpl('{expr}) }
def assert(expr: => Boolean): Unit

Expand Down
6 changes: 4 additions & 2 deletions compiler/test-resources/repl/i10355
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
scala> import scala.quoted._
scala> def foo(expr: Expr[Any])(using Quotes) = expr match { case '{ $x: t } => '{ $x: Any } }
def foo
(expr: quoted.Expr[Any])(using x$2: quoted.Quotes): scala.quoted.Expr[Any]
(expr: scala.quoted.Expr[Any])
(using x$2: scala.quoted.Quotes): scala.quoted.Expr[Any]
scala> def bar(expr: Expr[Any])(using Quotes) = expr match { case '{ $x: t } => '{ val a: t = ??? ; ???} }
def bar
(expr: quoted.Expr[Any])(using x$2: quoted.Quotes): scala.quoted.Expr[Nothing]
(expr: scala.quoted.Expr[Any])
(using x$2: scala.quoted.Quotes): scala.quoted.Expr[Nothing]
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@ class CompletionTest {

@Test def completionFromScalaPackage: Unit = {
code"class Foo { val foo: Conv${m1} }"
.completion(("Conversion", Class, "scala.Conversion"))
.completion(("Conversion", Class, "Conversion"))
}

@Test def completionFromScalaPackageObject: Unit = {
code"class Foo { val foo: BigD${m1} }"
.completion(
("BigDecimal", Field, "scala.BigDecimal"),
("BigDecimal", Method, "=> math.BigDecimal.type"),
("BigDecimal", Field, "BigDecimal"),
("BigDecimal", Method, "=> scala.math.BigDecimal.type"),
)
}

@Test def completionFromSyntheticPackageObject: Unit = {
code"class Foo { val foo: IArr${m1} }"
.completion(
("IArray", Module, "IArray"),
("IArray", Field, "scala.IArray"),
("IArray", Field, "IArray"),
)
}

@Test def completionFromJavaDefaults: Unit = {
code"class Foo { val foo: Runn${m1} }"
.completion(
("Runnable", Class, "java.lang.Runnable"),
("Runnable", Class, "Runnable"),
("Runnable", Module, "Runnable"),
)
}
Expand Down Expand Up @@ -971,7 +971,7 @@ class CompletionTest {
("implicitNotFound", Module, "scala.annotation.implicitNotFound"),
)
.completion(m2,
("main", Class, "scala.main"),
("main", Class, "main"),
("main", Module, "main"),
)

Expand Down
4 changes: 2 additions & 2 deletions staging/test-resources/repl-staging/i6007
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
scala> import scala.quoted._
scala> import quoted.staging.{Compiler => StagingCompiler, _}
scala> implicit def compiler: StagingCompiler = StagingCompiler.make(getClass.getClassLoader)
def compiler: quoted.staging.Compiler
def compiler: scala.quoted.staging.Compiler
scala> def v(using Quotes) = '{ (if true then Some(1) else None).map(v => v+1) }
def v(using x$1: quoted.Quotes): scala.quoted.Expr[Option[Int]]
def v(using x$1: scala.quoted.Quotes): scala.quoted.Expr[Option[Int]]
scala> scala.quoted.staging.withQuotes(v.show)
val res0: String = (if (true) scala.Some.apply[scala.Int](1) else scala.None).map[scala.Int](((v: scala.Int) => v.+(1)))
scala> scala.quoted.staging.run(v)
Expand Down
4 changes: 2 additions & 2 deletions staging/test-resources/repl-staging/i6263
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
scala> import quoted._
scala> import quoted.staging.{Compiler => StagingCompiler, _}
scala> implicit def compiler: StagingCompiler = StagingCompiler.make(getClass.getClassLoader)
def compiler: quoted.staging.Compiler
def compiler: scala.quoted.staging.Compiler
scala> def fn[T : Type](v : T) = println("ok")
def fn[T](v: T)(implicit evidence$1: quoted.Type[T]): Unit
def fn[T](v: T)(implicit evidence$1: scala.quoted.Type[T]): Unit
scala> withQuotes { fn("foo") }
ok
scala> withQuotes { fn((1,2)) }
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-custom-args/captures/cc-this2.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
-- Error: tests/neg-custom-args/captures/cc-this2/D_2.scala:2:6 --------------------------------------------------------
2 |class D extends C: // error
|^
|reference (scala.caps.cap : Any) is not included in allowed capture set {} of pure base class class C
|reference (caps.cap : Any) is not included in allowed capture set {} of pure base class class C
3 | this: D^ =>
2 changes: 1 addition & 1 deletion tests/neg-custom-args/captures/exception-definitions.check
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Error: tests/neg-custom-args/captures/exception-definitions.scala:2:6 -----------------------------------------------
2 |class Err extends Exception: // error
|^
|reference (scala.caps.cap : Any) is not included in allowed capture set {} of pure base class class Throwable
|reference (caps.cap : Any) is not included in allowed capture set {} of pure base class class Throwable
3 | self: Err^ =>
-- Error: tests/neg-custom-args/captures/exception-definitions.scala:10:6 ----------------------------------------------
10 |class Err4(c: Any^) extends AnyVal // error
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-custom-args/explain/i16888.check
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- [E172] Type Error: tests/neg-custom-args/explain/i16888.scala:1:38 --------------------------------------------------
1 |def test = summon[scala.quoted.Quotes] // error
| ^
| No given instance of type quoted.Quotes was found for parameter x of method summon in object Predef
| No given instance of type scala.quoted.Quotes was found for parameter x of method summon in object Predef
|---------------------------------------------------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/i14025.check
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- [E172] Type Error: tests/neg/i14025.scala:1:88 ----------------------------------------------------------------------
1 |val foo = summon[deriving.Mirror.Product { type MirroredType = [X] =>> [Y] =>> (X, Y) }] // error
| ^
|No given instance of type deriving.Mirror.Product{type MirroredType[X] = [Y] =>> (X, Y)} was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Product{type MirroredType[X] = [Y] =>> (X, Y)}: type `[X] =>> [Y] =>> (X, Y)` is not a generic product because its subpart `[X] =>> [Y] =>> (X, Y)` is not a supported kind (either `*` or `* -> *`)
|No given instance of type scala.deriving.Mirror.Product{type MirroredType[X] = [Y] =>> (X, Y)} was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type scala.deriving.Mirror.Product{type MirroredType[X] = [Y] =>> (X, Y)}: type `[X] =>> [Y] =>> (X, Y)` is not a generic product because its subpart `[X] =>> [Y] =>> (X, Y)` is not a supported kind (either `*` or `* -> *`)
-- [E172] Type Error: tests/neg/i14025.scala:2:90 ----------------------------------------------------------------------
2 |val bar = summon[deriving.Mirror.Sum { type MirroredType = [X] =>> [Y] =>> List[(X, Y)] }] // error
| ^
|No given instance of type deriving.Mirror.Sum{type MirroredType[X] = [Y] =>> List[(X, Y)]} was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Sum{type MirroredType[X] = [Y] =>> List[(X, Y)]}: type `[X] =>> [Y] =>> List[(X, Y)]` is not a generic sum because its subpart `[X] =>> [Y] =>> List[(X, Y)]` is not a supported kind (either `*` or `* -> *`)
|No given instance of type scala.deriving.Mirror.Sum{type MirroredType[X] = [Y] =>> List[(X, Y)]} was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type scala.deriving.Mirror.Sum{type MirroredType[X] = [Y] =>> List[(X, Y)]}: type `[X] =>> [Y] =>> List[(X, Y)]` is not a generic sum because its subpart `[X] =>> [Y] =>> List[(X, Y)]` is not a supported kind (either `*` or `* -> *`)
6 changes: 3 additions & 3 deletions tests/neg/i14127.check
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- [E172] Type Error: tests/neg/i14127.scala:6:55 ----------------------------------------------------------------------
6 | *: Int *: Int *: Int *: Int *: Int *: EmptyTuple)]] // error
| ^
|No given instance of type deriving.Mirror.Of[(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int,
| Int, Int, Int)] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int,
| Int, Int, Int)]:
|No given instance of type scala.deriving.Mirror.Of[(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int,
| Int, Int, Int, Int, Int)] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type scala.deriving.Mirror.Of[(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int,
| Int, Int, Int, Int, Int)]:
| * class *: is not a generic product because it reduces to a tuple with arity 23, expected arity <= 22
| * class *: is not a generic sum because it does not have subclasses
4 changes: 2 additions & 2 deletions tests/neg/i14363.check
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
|
| One of the following imports might fix the problem:
|
| import math.BigDecimal.int2bigDecimal
| import math.BigInt.int2bigInt
| import scala.math.BigDecimal.int2bigDecimal
| import scala.math.BigInt.int2bigInt
|
|
| longer explanation available when compiling with `-explain`
2 changes: 1 addition & 1 deletion tests/neg/i14432.check
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- [E172] Type Error: tests/neg/i14432.scala:13:33 ---------------------------------------------------------------------
13 |val mFoo = summon[Mirror.Of[Foo]] // error: no mirror found
| ^
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[example.Foo]:
|No given instance of type scala.deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type scala.deriving.Mirror.Of[example.Foo]:
| * class Foo is not a generic product because the constructor of class Foo is innaccessible from the calling scope.
| * class Foo is not a generic sum because it is not a sealed class
2 changes: 1 addition & 1 deletion tests/neg/i14432a.check
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- [E172] Type Error: tests/neg/i14432a.scala:14:43 --------------------------------------------------------------------
14 | val mFoo = summon[Mirror.Of[example.Foo]] // error: no mirror found
| ^
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[example.Foo]:
|No given instance of type scala.deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type scala.deriving.Mirror.Of[example.Foo]:
| * class Foo is not a generic product because the constructor of class Foo is innaccessible from the calling scope.
| * class Foo is not a generic sum because it is not a sealed class
2 changes: 1 addition & 1 deletion tests/neg/i14432b.check
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- [E172] Type Error: tests/neg/i14432b.scala:15:43 --------------------------------------------------------------------
15 | val mFoo = summon[Mirror.Of[example.Foo]] // error: no mirror found
| ^
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[example.Foo]:
|No given instance of type scala.deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type scala.deriving.Mirror.Of[example.Foo]:
| * class Foo is not a generic product because the constructor of class Foo is innaccessible from the calling scope.
| * class Foo is not a generic sum because it is not a sealed class
2 changes: 1 addition & 1 deletion tests/neg/i14432c.check
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
-- [E172] Type Error: tests/neg/i14432c.scala:16:43 --------------------------------------------------------------------
16 | val mFoo = summon[Mirror.Of[example.Foo]] // error: no mirror
| ^
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[example.Foo]:
|No given instance of type scala.deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type scala.deriving.Mirror.Of[example.Foo]:
| * class Foo is not a generic product because the constructor of class Foo is innaccessible from the calling scope.
| * class Foo is not a generic sum because it is not a sealed class
2 changes: 1 addition & 1 deletion tests/neg/i14432d.check
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- [E172] Type Error: tests/neg/i14432d.scala:17:45 --------------------------------------------------------------------
17 | val mFoo = summon[Mirror.Of[example.Foo]] // error
| ^
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[example.Foo]:
|No given instance of type scala.deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type scala.deriving.Mirror.Of[example.Foo]:
| * class Foo is not a generic product because the constructor of class Foo is innaccessible from the calling scope.
| * class Foo is not a generic sum because it is not a sealed class
6 changes: 3 additions & 3 deletions tests/neg/i14564.check
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
|
| One of the following imports might make progress towards fixing the problem:
|
| import math.Fractional.Implicits.infixFractionalOps
| import math.Integral.Implicits.infixIntegralOps
| import math.Numeric.Implicits.infixNumericOps
| import scala.math.Fractional.Implicits.infixFractionalOps
| import scala.math.Integral.Implicits.infixIntegralOps
| import scala.math.Numeric.Implicits.infixNumericOps
|
2 changes: 1 addition & 1 deletion tests/neg/i14823.check
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- [E172] Type Error: tests/neg/i14823.scala:8:50 ----------------------------------------------------------------------
8 |val baz = summon[Mirror.Of[SubA[Int] | SubB[Int]]] // error
| ^
|No given instance of type deriving.Mirror.Of[SubA[Int] | SubB[Int]] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[SubA[Int] | SubB[Int]]:
|No given instance of type scala.deriving.Mirror.Of[SubA[Int] | SubB[Int]] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type scala.deriving.Mirror.Of[SubA[Int] | SubB[Int]]:
| * type `SubA[Int] | SubB[Int]` is not a generic product because its subpart `SubA[Int] | SubB[Int]` is a top-level union type.
| * type `SubA[Int] | SubB[Int]` is not a generic sum because its subpart `SubA[Int] | SubB[Int]` is a top-level union type.
6 changes: 3 additions & 3 deletions tests/neg/i14823a.check
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- [E172] Type Error: tests/neg/i14823a.scala:16:48 --------------------------------------------------------------------
16 |val foo = summon[Mirror.Of[Box[Int] | Box[Int]]] // error
| ^
|No given instance of type deriving.Mirror.Of[Box[Int] | Box[Int]] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[Box[Int] | Box[Int]]:
|No given instance of type scala.deriving.Mirror.Of[Box[Int] | Box[Int]] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type scala.deriving.Mirror.Of[Box[Int] | Box[Int]]:
| * type `Box[Int] | Box[Int]` is not a generic product because its subpart `Box[Int] | Box[Int]` is a top-level union type.
| * type `Box[Int] | Box[Int]` is not a generic sum because its subpart `Box[Int] | Box[Int]` is a top-level union type.
-- [E172] Type Error: tests/neg/i14823a.scala:17:58 --------------------------------------------------------------------
Expand All @@ -13,12 +13,12 @@
-- [E172] Type Error: tests/neg/i14823a.scala:18:63 --------------------------------------------------------------------
18 |def baz = summon[deriving.Mirror.Of[Foo[String] | Foo[String]]] // error
| ^
|No given instance of type deriving.Mirror.Of[Foo[String] | Foo[String]] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[Foo[String] | Foo[String]]:
|No given instance of type scala.deriving.Mirror.Of[Foo[String] | Foo[String]] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type scala.deriving.Mirror.Of[Foo[String] | Foo[String]]:
| * type `Foo[String] | Foo[String]` is not a generic product because its subpart `Foo[String] | Foo[String]` is a top-level union type.
| * type `Foo[String] | Foo[String]` is not a generic sum because its subpart `Foo[String] | Foo[String]` is a top-level union type.
-- [E172] Type Error: tests/neg/i14823a.scala:20:66 --------------------------------------------------------------------
20 |def qux = summon[deriving.Mirror.Of[Option[Int] | Option[String]]] // error
| ^
|No given instance of type deriving.Mirror.Of[Option[Int] | Option[String]] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[Option[Int] | Option[String]]:
|No given instance of type scala.deriving.Mirror.Of[Option[Int] | Option[String]] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type scala.deriving.Mirror.Of[Option[Int] | Option[String]]:
| * type `Option[Int] | Option[String]` is not a generic product because its subpart `Option[Int] | Option[String]` is a top-level union type.
| * type `Option[Int] | Option[String]` is not a generic sum because its subpart `Option[Int] | Option[String]` is a top-level union type.
4 changes: 2 additions & 2 deletions tests/neg/i4986a.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
|Cannot construct a collection of type List[String] with elements of type Int based on a collection of type List[Int]..
|I found:
|
| collection.BuildFrom.buildFromIterableOps[CC, A0, A]
| scala.collection.BuildFrom.buildFromIterableOps[CC, A0, A]
|
|But method buildFromIterableOps in trait BuildFromLowPriority2 does not match type collection.BuildFrom[List[Int], Int, List[String]].
|But method buildFromIterableOps in trait BuildFromLowPriority2 does not match type scala.collection.BuildFrom[List[Int], Int, List[String]].
Loading