Skip to content

Commit

Permalink
Print full package names, even if they're TermRefs
Browse files Browse the repository at this point in the history
If you refer to a package by name, e.g. `scala.quoted.Quotes`, the type
may have a "quoted" prefix that is a TermRef.  Rather than unravel the
rest of the prefixes, we print the fully package name.

[Cherry-picked c04bb4f]
  • Loading branch information
dwijnand authored and Kordyjan committed Nov 17, 2023
1 parent 20113f4 commit a114971
Show file tree
Hide file tree
Showing 26 changed files with 60 additions and 54 deletions.
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,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)
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 @@ -39,7 +39,7 @@ class CompletionTest {
code"class Foo { val foo: BigD${m1} }"
.completion(
("BigDecimal", Field, "BigDecimal"),
("BigDecimal", Method, "=> math.BigDecimal.type"),
("BigDecimal", Method, "=> scala.math.BigDecimal.type"),
)
}

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/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

0 comments on commit a114971

Please sign in to comment.