Skip to content

Commit 104e8df

Browse files
authored
Merge pull request #15899 from Sporarum/fix-plainprinter
Fix PlainPrinter.scala: Incorrect type parameters
2 parents 63344e7 + cfbca8c commit 104e8df

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
@@ -232,7 +232,8 @@ class PlainPrinter(_ctx: Context) extends Printer {
232232
~ keywordText("erased ").provided(tp.isErasedMethod)
233233
~ keywordText("implicit ").provided(tp.isImplicitMethod && !tp.isContextualMethod)
234234
~ paramsText(tp)
235-
~ (if tp.resultType.isInstanceOf[MethodType] then ")" else "): ")
235+
~ ")"
236+
~ (Str(": ") provided !tp.resultType.isInstanceOf[MethodOrPoly])
236237
~ toText(tp.resultType)
237238
}
238239
case ExprType(ct @ EventuallyCapturingType(parent, refs))
@@ -250,7 +251,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
250251
case tp: PolyType =>
251252
changePrec(GlobalPrec) {
252253
"[" ~ paramsText(tp) ~ "]" ~ lambdaHash(tp) ~
253-
(Str(" => ") provided !tp.resultType.isInstanceOf[MethodType]) ~
254+
(Str(": ") provided !tp.resultType.isInstanceOf[MethodOrPoly]) ~
254255
toTextGlobal(tp.resultType)
255256
}
256257
case AnnotatedType(tpe, annot) =>
@@ -450,7 +451,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
450451
(if (isParameter) ": => " else ": ") ~ toTextGlobal(tp.widenExpr)
451452
case tp: PolyType =>
452453
"[" ~ paramsText(tp) ~ "]"
453-
~ (Str(": ") provided !tp.resultType.isInstanceOf[MethodType])
454+
~ (Str(": ") provided !tp.resultType.isInstanceOf[MethodOrPoly])
454455
~ toTextGlobal(tp.resultType)
455456
case tp =>
456457
": " ~ 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)