Skip to content

Commit 0e761ea

Browse files
authored
Merge pull request #7706 from dotty-staging/fix-#7634
Fix #7634: Use `(x: C)` instead of `C(x)` for printing singleton types
2 parents c49ae36 + 9775231 commit 0e761ea

File tree

9 files changed

+24
-24
lines changed

9 files changed

+24
-24
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
229229
}.close
230230

231231
def toTextSingleton(tp: SingletonType): Text =
232-
toTextLocal(tp.underlying) ~ "(" ~ toTextRef(tp) ~ ")"
232+
"(" ~ toTextRef(tp) ~ " : " ~ toTextGlobal(tp.underlying) ~ ")"
233233

234234
protected def paramsText(tp: LambdaType): Text = {
235235
def paramText(name: Name, tp: Type) = toText(name) ~ toTextRHS(tp)

compiler/test-resources/repl/errmsgs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ scala> class Inv[T](x: T)
33
scala> val x: List[String] = List(1)
44
1 | val x: List[String] = List(1)
55
| ^
6-
| Found: Int(1)
6+
| Found: (1 : Int)
77
| Required: String
88
scala> val y: List[List[String]] = List(List(1))
99
1 | val y: List[List[String]] = List(List(1))
1010
| ^
11-
| Found: Int(1)
11+
| Found: (1 : Int)
1212
| Required: String
1313
scala> val z: (List[String], List[Int]) = (List(1), List("a"))
1414
1 | val z: (List[String], List[Int]) = (List(1), List("a"))
1515
| ^
16-
| Found: Int(1)
16+
| Found: (1 : Int)
1717
| Required: String
1818
1 | val z: (List[String], List[Int]) = (List(1), List("a"))
1919
| ^^^
20-
| Found: String("a")
21-
| Required: Int
20+
| Found: ("a" : String)
21+
| Required: Int
2222
scala> val a: Inv[String] = new Inv(new Inv(1))
2323
1 | val a: Inv[String] = new Inv(new Inv(1))
2424
| ^^^^^^^^^^
@@ -27,19 +27,19 @@ scala> val a: Inv[String] = new Inv(new Inv(1))
2727
scala> val b: Inv[String] = new Inv(1)
2828
1 | val b: Inv[String] = new Inv(1)
2929
| ^
30-
| Found: Int(1)
30+
| Found: (1 : Int)
3131
| Required: String
3232
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() } }; }
3333
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() } }; }
3434
| ^
35-
|Found: C.this.T(C.this.x)
35+
|Found: (C.this.x : C.this.T)
3636
|Required: T²
3737
|
3838
|where: T is a type in class C
3939
| T² is a type in the initializer of value s which is an alias of String
4040
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() } }; }
4141
| ^
42-
|Found: T(y)
42+
|Found: (y : T)
4343
|Required: T²
4444
|
4545
|where: T is a type in the initializer of value s which is an alias of String
@@ -51,7 +51,7 @@ scala> class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
5151
scala> val x: List[Int] = "foo" :: List(1)
5252
1 | val x: List[Int] = "foo" :: List(1)
5353
| ^^^^^
54-
| Found: String("foo")
54+
| Found: ("foo" : String)
5555
| Required: Int
5656
scala> while ((( foo ))) {}
5757
1 | while ((( foo ))) {}

compiler/test-resources/repl/importFromObj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ scala> import o._
77
scala> buf += xs
88
1 | buf += xs
99
| ^^
10-
| Found: List[Int](o.xs)
10+
| Found: (o.xs : List[Int])
1111
| Required: Int
1212
scala> buf ++= xs
1313
val res0: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3)

compiler/test-resources/type-printer/type-mismatch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ val res0: Foo[Int] = Foo(1)
55
scala> val x: Foo[String] = res0
66
1 | val x: Foo[String] = res0
77
| ^^^^
8-
| Found: Foo[Int](res0)
8+
| Found: (res0 : Foo[Int])
99
| Required: Foo[String]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class DiagnosticsTest {
1212
| val x: Int = $m1"foo"$m2
1313
|}""".withSource
1414
.diagnostics(m1,
15-
(m1 to m2, """Found: String("foo")
15+
(m1 to m2, """Found: ("foo" : String)
1616
|Required: Int""".stripMargin, Error, Some(TypeMismatchID))
1717
)
1818

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,24 @@ class HoverTest {
4646
| ${m1}val x = ${m2}8$m3; ${m4}x$m5
4747
|}""".withSource
4848
.hover(m1 to m2, hoverContent("Int"))
49-
.hover(m2 to m3, hoverContent("Int(8)"))
49+
.hover(m2 to m3, hoverContent("(8 : Int)"))
5050
.hover(m4 to m5, hoverContent("Int"))
5151
}
5252

5353
@Test def hoverOnValDef1: Unit = {
5454
code"""class Foo {
5555
| ${m1}final val x = 8$m2; ${m3}x$m4
5656
|}""".withSource
57-
.hover(m1 to m2, hoverContent("Int(8)"))
58-
.hover(m3 to m4, hoverContent("Int(8)"))
57+
.hover(m1 to m2, hoverContent("(8 : Int)"))
58+
.hover(m3 to m4, hoverContent("(8 : Int)"))
5959
}
6060

6161
@Test def hoverOnDefDef0: Unit = {
6262
code"""class Foo {
6363
| ${m1}def x = ${m2}8$m3; ${m4}x$m5
6464
|}""".withSource
6565
.hover(m1 to m2, hoverContent("Int"))
66-
.hover(m2 to m3, hoverContent("Int(8)"))
66+
.hover(m2 to m3, hoverContent("(8 : Int)"))
6767
.hover(m4 to m5, hoverContent("Int"))
6868
}
6969

@@ -83,7 +83,7 @@ class HoverTest {
8383
| ${m5}y($m6)$m7
8484
|}
8585
""".withSource
86-
.hover(m1 to m2, hoverContent("String(\"abc\")" ))
86+
.hover(m1 to m2, hoverContent("(\"abc\" : String)"))
8787
.hover(m3 to m4, hoverContent("String"))
8888
.hover(m5 to m6, hoverContent("(): Int"))
8989
.hover(m6 to m7, hoverContent("Int"))
@@ -185,8 +185,8 @@ class HoverTest {
185185
|class annot4 extends scala.annotation.Annotation
186186
|class annot5 extends scala.annotation.Annotation
187187
|""".withSource
188-
.hover(m1 to m2, hoverContent("Int(1)"))
189-
.hover(m3 to m4, hoverContent("Int(1) @annot1 @annot2 @annot3 @annot4 @annot5"))
188+
.hover(m1 to m2, hoverContent("(1 : Int)"))
189+
.hover(m3 to m4, hoverContent("(1 : Int) @annot1 @annot2 @annot3 @annot4 @annot5"))
190190
}
191191

192192
@Test def unicodeChar: Unit = {
@@ -207,6 +207,6 @@ class HoverTest {
207207
|val y = ${m1}this${m2}.x""".withSource
208208
// The test framework will place the code above in a virtual file called Source0.scala,
209209
// sp the top-level definitions should be enclosed in an object called `Source0$package`.
210-
.hover(m1 to m2, hoverContent("hello.Source0$package.type(hello.Source0$package)"))
210+
.hover(m1 to m2, hoverContent("(hello.Source0$package : hello.Source0$package.type)"))
211211
}
212212
}

tests/neg/cannot-reduce-inline-match.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
| cannot reduce inline match with
55
| scrutinee: {
66
| "f"
7-
| } : String("f")
7+
| } : ("f" : String)
88
| patterns : case _:Int
99
| This location contains code that was inlined from cannot-reduce-inline-match.scala:3

tests/neg/exports.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@
5252
| ^
5353
| Double definition:
5454
| val bar: Bar in class Baz at line 45 and
55-
| final def bar: => => Bar(Baz.this.bar.baz.bar)(Baz.this.bar.bar) in class Baz at line 46
55+
| final def bar: => (Baz.this.bar.bar : => (Baz.this.bar.baz.bar : Bar)) in class Baz at line 46

tests/neg/inline-error-pos.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
| cannot reduce inline match with
55
| scrutinee: {
66
| 2
7-
| } : Int(2)
7+
| } : (2 : Int)
88
| patterns : case 1
99
| This location contains code that was inlined from inline-error-pos.scala:3

0 commit comments

Comments
 (0)