Skip to content

Commit cfbca8c

Browse files
committed
Fix PlainPrinter.scala: incorect type pararameters
What it prints might be counter intuitive at first, but is correct The clearest example is in i5345, where otherwise the printed output doesn't correspond to the declaration
1 parent 6234966 commit cfbca8c

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ class PlainPrinter(_ctx: Context) extends Printer {
211211
~ keywordText("erased ").provided(tp.isErasedMethod)
212212
~ keywordText("implicit ").provided(tp.isImplicitMethod && !tp.isContextualMethod)
213213
~ paramsText(tp)
214-
~ (if tp.resultType.isInstanceOf[MethodType] then ")" else "): ")
214+
~ ")"
215+
~ (Str(": ") provided !tp.resultType.isInstanceOf[MethodOrPoly])
215216
~ toText(tp.resultType)
216217
}
217218
case tp: ExprType =>
@@ -223,7 +224,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
223224
case tp: PolyType =>
224225
changePrec(GlobalPrec) {
225226
"[" ~ paramsText(tp) ~ "]" ~ lambdaHash(tp) ~
226-
(Str(" => ") provided !tp.resultType.isInstanceOf[MethodType]) ~
227+
(Str(": ") provided !tp.resultType.isInstanceOf[MethodOrPoly]) ~
227228
toTextGlobal(tp.resultType)
228229
}
229230
case AnnotatedType(tpe, annot) =>
@@ -418,7 +419,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
418419
(if (isParameter) ": => " else ": ") ~ toTextGlobal(tp.widenExpr)
419420
case tp: PolyType =>
420421
"[" ~ paramsText(tp) ~ "]"
421-
~ (Str(": ") provided !tp.resultType.isInstanceOf[MethodType])
422+
~ (Str(": ") provided !tp.resultType.isInstanceOf[MethodOrPoly])
422423
~ toTextGlobal(tp.resultType)
423424
case tp =>
424425
": " ~ toTextGlobal(tp)

compiler/test-resources/repl/i5345

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
scala> def x[A, B]: Conversion[A, B] = _ => ???
2-
def x[A, B] => Conversion[A, B]
2+
def x[A, B]: Conversion[A, B]

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ class CompletionTest {
643643
code"""object Foo
644644
|extension (foo: Foo.type) def xxxx[A]: Int = 1
645645
|object Main { Foo.xx${m1} }"""
646-
.completion(("xxxx", Method, "[A] => Int"))
646+
.completion(("xxxx", Method, "[A]: Int"))
647647
}
648648

649649
@Test def completeExtensionMethodWithParameterAndTypeParameter: Unit = {
@@ -762,7 +762,7 @@ class CompletionTest {
762762
|given Baz with {}
763763
|extension [A](using bar: Bar)(a: A)(using baz: Baz) def xxxx[B]: Either[A, B] = Left(a)
764764
|object Main { 123.xx${m1} }"""
765-
.completion(("xxxx", Method, "(using baz: Baz): [B] => Either[Int, B]"))
765+
.completion(("xxxx", Method, "(using baz: Baz)[B]: Either[Int, B]"))
766766
}
767767

768768
@Test def completeExtensionMethodWithTypeBounds: Unit = {
@@ -772,7 +772,7 @@ class CompletionTest {
772772
|extension [A >: Bar](a: A) def xxxx[B <: a.type]: Either[A, B] = Left(a)
773773
|val foo = new Foo {}
774774
|object Main { foo.xx${m1} }"""
775-
.completion(("xxxx", Method, "[B <: (foo : Foo)] => Either[Foo, B]"))
775+
.completion(("xxxx", Method, "[B <: (foo : Foo)]: Either[Foo, B]"))
776776
}
777777

778778
@Test def completeInheritedExtensionMethod: Unit = {
@@ -1034,15 +1034,15 @@ class CompletionTest {
10341034
("", Method, "[B](y: B): (A, B)"),
10351035
("!=", Method, "(x$0: Any): Boolean"),
10361036
("fromOrdinal", Method, "(ordinal: Int): Foo.Bar"),
1037-
("asInstanceOf", Method, "[X0] => X0"),
1037+
("asInstanceOf", Method, "[X0]: X0"),
10381038
("->", Method, "[B](y: B): (A, B)"),
10391039
("wait", Method, "(x$0: Long, x$1: Int): Unit"),
10401040
("`back-tick`", Field, "Foo.Bar"),
10411041
("notify", Method, "(): Unit"),
10421042
("formatted", Method, "(fmtstr: String): String"),
10431043
("ensuring", Method, "(cond: A => Boolean, msg: => Any): A"),
10441044
("wait", Method, "(): Unit"),
1045-
("isInstanceOf", Method, "[X0] => Boolean"),
1045+
("isInstanceOf", Method, "[X0]: Boolean"),
10461046
("`match`", Field, "Foo.Bar"),
10471047
("toString", Method, "(): String"),
10481048
("ensuring", Method, "(cond: A => Boolean): A"),

tests/neg-custom-args/fatal-warnings/i9408a.check

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-- Error: tests/neg-custom-args/fatal-warnings/i9408a.scala:26:20 ------------------------------------------------------
1010
26 | val length: Int = "qwerty" // error
1111
| ^^^^^^^^
12-
|The conversion (Test5.implicitLength : [A] => String => Int) will not be applied implicitly here in Scala 3 because only implicit methods and instances of Conversion class will continue to work as implicit views.
12+
|The conversion (Test5.implicitLength : [A]: String => Int) will not be applied implicitly here in Scala 3 because only implicit methods and instances of Conversion class will continue to work as implicit views.
1313
-- Error: tests/neg-custom-args/fatal-warnings/i9408a.scala:31:20 ------------------------------------------------------
1414
31 | val length: Int = "qwerty" // error
1515
| ^^^^^^^^
@@ -21,4 +21,4 @@
2121
-- Error: tests/neg-custom-args/fatal-warnings/i9408a.scala:59:2 -------------------------------------------------------
2222
59 | 123.foo // error
2323
| ^^^
24-
|The conversion (Test11.a2foo : [A] => A => Test11.Foo) will not be applied implicitly here in Scala 3 because only implicit methods and instances of Conversion class will continue to work as implicit views.
24+
|The conversion (Test11.a2foo : [A]: A => Test11.Foo) will not be applied implicitly here in Scala 3 because only implicit methods and instances of Conversion class will continue to work as implicit views.

0 commit comments

Comments
 (0)