Skip to content

Commit a464be3

Browse files
griggtSethTisue
andcommitted
Improve appearance of error messages that include polymorphic method types
Fixes #13466 Co-authored-by: Seth Tisue <[email protected]>
1 parent cca4732 commit a464be3

File tree

7 files changed

+30
-6
lines changed

7 files changed

+30
-6
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ class PlainPrinter(_ctx: Context) extends Printer {
404404
case tp: ExprType =>
405405
// parameterless methods require special treatment, see #11201
406406
(if (isParameter) ": => " else ": ") ~ toTextGlobal(tp.widenExpr)
407+
case tp: PolyType =>
408+
"[" ~ paramsText(tp) ~ "]"
409+
~ (Str(": ") provided !tp.resultType.isInstanceOf[MethodType])
410+
~ toTextGlobal(tp.resultType)
407411
case tp =>
408412
": " ~ toTextGlobal(tp)
409413
}

tests/neg/i10666.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
-- Error: tests/neg/i10666.scala:8:6 -----------------------------------------------------------------------------------
22
8 |class Bar extends Foo { // error
33
| ^
4-
| class Bar needs to be abstract, since def foo: [T <: B](tx: T): Unit in trait Foo is not defined
4+
| class Bar needs to be abstract, since def foo[T <: B](tx: T): Unit in trait Foo is not defined
55
| (Note that
6-
| parameter T in def foo: [T <: B](tx: T): Unit in trait Foo does not match
7-
| parameter T in def foo: [T <: A](tx: T): Unit in class Bar
6+
| parameter T in def foo[T <: B](tx: T): Unit in trait Foo does not match
7+
| parameter T in def foo[T <: A](tx: T): Unit in class Bar
88
| class B is a subclass of class A, but method parameter types must match exactly.)

tests/neg/i13466.check

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Error: tests/neg/i13466.scala:9:6 -----------------------------------------------------------------------------------
2+
9 |given none: SomeTrait[Finally] with {} // error
3+
| ^
4+
| object creation impossible, since:
5+
| it has 3 unimplemented members.
6+
| /** As seen from module class none$, the missing signatures are as follows.
7+
| * For convenience, these are usable as stub implementations.
8+
| */
9+
| def foo: Finally[Unit] = ???
10+
| def withTV[A]: Finally[A] = ???
11+
| def withTV2[A, B]: Finally[(A, B)] = ???

tests/neg/i13466.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
opaque type Finally[A] = A
2+
3+
trait SomeTrait[F[_]] {
4+
def foo: F[Unit]
5+
def withTV[A]: F[A]
6+
def withTV2[A, B]: F[(A, B)]
7+
}
8+
9+
given none: SomeTrait[Finally] with {} // error

tests/neg/i7359-f.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
1 |trait SAMTrait: // error
33
| ^
44
| Name clash between inherited members:
5-
| def equals: [T >: Boolean <: Boolean](obj: Any): T in trait SAMTrait at line 3 and
5+
| def equals[T >: Boolean <: Boolean](obj: Any): T in trait SAMTrait at line 3 and
66
| def equals(x$0: Any): Boolean in class Any
77
| have the same type after erasure.
88
|

tests/neg/mixin-forwarder-clash1.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
| ^
44
| Name clash between inherited members:
55
| def concat(suffix: Int): X in trait One at line 4 and
6-
| def concat: [Dummy](suffix: Int): Y in trait Two at line 8
6+
| def concat[Dummy](suffix: Int): Y in trait Two at line 8
77
| have the same type after erasure.
88
|
99
| Consider adding a @targetName annotation to one of the conflicting definitions

tests/neg/mixin-forwarder-clash2.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
| ^
55
| Name clash between inherited members:
66
| def concat(suffix: Int): X in trait One at line 4 and
7-
| def concat: [Dummy](suffix: Int): Y in trait Two at line 8
7+
| def concat[Dummy](suffix: Int): Y in trait Two at line 8
88
| have the same type after erasure.
99
|
1010
| Consider adding a @targetName annotation to one of the conflicting definitions

0 commit comments

Comments
 (0)