Skip to content

Commit fed2764

Browse files
committed
Print erased type in double definition message
Print erased type if the message says "have the same type after erasure"
1 parent 8d1c435 commit fed2764

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2128,6 +2128,7 @@ import transform.SymUtils._
21282128
class DoubleDefinition(decl: Symbol, previousDecl: Symbol, base: Symbol)(using Context) extends NamingMsg(DoubleDefinitionID) {
21292129
def msg = {
21302130
def nameAnd = if (decl.name != previousDecl.name) " name and" else ""
2131+
def erasedType = if ctx.erasedTypes then i" ${decl.info}" else ""
21312132
def details(using Context): String =
21322133
if (decl.isRealMethod && previousDecl.isRealMethod) {
21332134
import Signature.MatchDegree._
@@ -2155,7 +2156,7 @@ import transform.SymUtils._
21552156
|Consider adding a @targetName annotation to one of the conflicting definitions
21562157
|for disambiguation."""
21572158
else ""
2158-
i"have the same$nameAnd type after erasure.$hint"
2159+
i"have the same$nameAnd type$erasedType after erasure.$hint"
21592160
}
21602161
}
21612162
else ""

tests/neg/i14966a.check

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- [E120] Naming Error: tests/neg/i14966a.scala:3:6 --------------------------------------------------------------------
2+
3 | def f(x: List[Int]): String = ??? // error
3+
| ^
4+
| Double definition:
5+
| def f[X <: String](x: List[X]): String in class Test at line 2 and
6+
| def f(x: List[Int]): String in class Test at line 3
7+
| have the same type (x: scala.collection.immutable.List): String after erasure.
8+
|
9+
| Consider adding a @targetName annotation to one of the conflicting definitions
10+
| for disambiguation.

tests/neg/i14966a.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Test:
2+
def f[X <: String](x: List[X]): String = ???
3+
def f(x: List[Int]): String = ??? // error
4+

0 commit comments

Comments
 (0)