Skip to content

Fix #7634: Use (x: C) instead of C(x) for printing singleton types #7706

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

Merged
merged 3 commits into from
Dec 9, 2019
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
}.close

def toTextSingleton(tp: SingletonType): Text =
toTextLocal(tp.underlying) ~ "(" ~ toTextRef(tp) ~ ")"
"(" ~ toTextRef(tp) ~ " : " ~ toTextGlobal(tp.underlying) ~ ")"

protected def paramsText(tp: LambdaType): Text = {
def paramText(name: Name, tp: Type) = toText(name) ~ toTextRHS(tp)
Expand Down
18 changes: 9 additions & 9 deletions compiler/test-resources/repl/errmsgs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ scala> class Inv[T](x: T)
scala> val x: List[String] = List(1)
1 | val x: List[String] = List(1)
| ^
| Found: Int(1)
| Found: (1 : Int)
| Required: String
scala> val y: List[List[String]] = List(List(1))
1 | val y: List[List[String]] = List(List(1))
| ^
| Found: Int(1)
| Found: (1 : Int)
| Required: String
scala> val z: (List[String], List[Int]) = (List(1), List("a"))
1 | val z: (List[String], List[Int]) = (List(1), List("a"))
| ^
| Found: Int(1)
| Found: (1 : Int)
| Required: String
1 | val z: (List[String], List[Int]) = (List(1), List("a"))
| ^^^
| Found: String("a")
| Required: Int
| Found: ("a" : String)
| Required: Int
scala> val a: Inv[String] = new Inv(new Inv(1))
1 | val a: Inv[String] = new Inv(new Inv(1))
| ^^^^^^^^^^
Expand All @@ -27,19 +27,19 @@ scala> val a: Inv[String] = new Inv(new Inv(1))
scala> val b: Inv[String] = new Inv(1)
1 | val b: Inv[String] = new Inv(1)
| ^
| Found: Int(1)
| Found: (1 : Int)
| Required: String
scala> abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
1 | abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
| ^
|Found: C.this.T(C.this.x)
|Found: (C.this.x : C.this.T)
|Required: T²
|
|where: T is a type in class C
| T² is a type in the initializer of value s which is an alias of String
1 | abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
| ^
|Found: T(y)
|Found: (y : T)
|Required: T²
|
|where: T is a type in the initializer of value s which is an alias of String
Expand All @@ -51,7 +51,7 @@ scala> class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
scala> val x: List[Int] = "foo" :: List(1)
1 | val x: List[Int] = "foo" :: List(1)
| ^^^^^
| Found: String("foo")
| Found: ("foo" : String)
| Required: Int
scala> while ((( foo ))) {}
1 | while ((( foo ))) {}
Expand Down
2 changes: 1 addition & 1 deletion compiler/test-resources/repl/importFromObj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ scala> import o._
scala> buf += xs
1 | buf += xs
| ^^
| Found: List[Int](o.xs)
| Found: (o.xs : List[Int])
| Required: Int
scala> buf ++= xs
val res0: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3)
Expand Down
2 changes: 1 addition & 1 deletion compiler/test-resources/type-printer/type-mismatch
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ val res0: Foo[Int] = Foo(1)
scala> val x: Foo[String] = res0
1 | val x: Foo[String] = res0
| ^^^^
| Found: Foo[Int](res0)
| Found: (res0 : Foo[Int])
| Required: Foo[String]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DiagnosticsTest {
| val x: Int = $m1"foo"$m2
|}""".withSource
.diagnostics(m1,
(m1 to m2, """Found: String("foo")
(m1 to m2, """Found: ("foo" : String)
|Required: Int""".stripMargin, Error, Some(TypeMismatchID))
)

Expand Down
16 changes: 8 additions & 8 deletions language-server/test/dotty/tools/languageserver/HoverTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ class HoverTest {
| ${m1}val x = ${m2}8$m3; ${m4}x$m5
|}""".withSource
.hover(m1 to m2, hoverContent("Int"))
.hover(m2 to m3, hoverContent("Int(8)"))
.hover(m2 to m3, hoverContent("(8 : Int)"))
.hover(m4 to m5, hoverContent("Int"))
}

@Test def hoverOnValDef1: Unit = {
code"""class Foo {
| ${m1}final val x = 8$m2; ${m3}x$m4
|}""".withSource
.hover(m1 to m2, hoverContent("Int(8)"))
.hover(m3 to m4, hoverContent("Int(8)"))
.hover(m1 to m2, hoverContent("(8 : Int)"))
.hover(m3 to m4, hoverContent("(8 : Int)"))
}

@Test def hoverOnDefDef0: Unit = {
code"""class Foo {
| ${m1}def x = ${m2}8$m3; ${m4}x$m5
|}""".withSource
.hover(m1 to m2, hoverContent("Int"))
.hover(m2 to m3, hoverContent("Int(8)"))
.hover(m2 to m3, hoverContent("(8 : Int)"))
.hover(m4 to m5, hoverContent("Int"))
}

Expand All @@ -83,7 +83,7 @@ class HoverTest {
| ${m5}y($m6)$m7
|}
""".withSource
.hover(m1 to m2, hoverContent("String(\"abc\")" ))
.hover(m1 to m2, hoverContent("(\"abc\" : String)"))
.hover(m3 to m4, hoverContent("String"))
.hover(m5 to m6, hoverContent("(): Int"))
.hover(m6 to m7, hoverContent("Int"))
Expand Down Expand Up @@ -185,8 +185,8 @@ class HoverTest {
|class annot4 extends scala.annotation.Annotation
|class annot5 extends scala.annotation.Annotation
|""".withSource
.hover(m1 to m2, hoverContent("Int(1)"))
.hover(m3 to m4, hoverContent("Int(1) @annot1 @annot2 @annot3 @annot4 @annot5"))
.hover(m1 to m2, hoverContent("(1 : Int)"))
.hover(m3 to m4, hoverContent("(1 : Int) @annot1 @annot2 @annot3 @annot4 @annot5"))
}

@Test def unicodeChar: Unit = {
Expand All @@ -207,6 +207,6 @@ class HoverTest {
|val y = ${m1}this${m2}.x""".withSource
// The test framework will place the code above in a virtual file called Source0.scala,
// sp the top-level definitions should be enclosed in an object called `Source0$package`.
.hover(m1 to m2, hoverContent("hello.Source0$package.type(hello.Source0$package)"))
.hover(m1 to m2, hoverContent("(hello.Source0$package : hello.Source0$package.type)"))
}
}
2 changes: 1 addition & 1 deletion tests/neg/cannot-reduce-inline-match.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
| cannot reduce inline match with
| scrutinee: {
| "f"
| } : String("f")
| } : ("f" : String)
| patterns : case _:Int
| This location contains code that was inlined from cannot-reduce-inline-match.scala:3
2 changes: 1 addition & 1 deletion tests/neg/exports.check
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
| ^
| Double definition:
| val bar: Bar in class Baz at line 45 and
| final def bar: => => Bar(Baz.this.bar.baz.bar)(Baz.this.bar.bar) in class Baz at line 46
| final def bar: => (Baz.this.bar.bar : => (Baz.this.bar.baz.bar : Bar)) in class Baz at line 46
2 changes: 1 addition & 1 deletion tests/neg/inline-error-pos.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
| cannot reduce inline match with
| scrutinee: {
| 2
| } : Int(2)
| } : (2 : Int)
| patterns : case 1
| This location contains code that was inlined from inline-error-pos.scala:3