Skip to content

Commit 811d127

Browse files
committed
Add hint to error message
In case of a double definition error that's due to an erasure clash, add a hint that one can resolve it with a @TargetNAME annotation
1 parent 0421a23 commit 811d127

File tree

7 files changed

+31
-1
lines changed

7 files changed

+31
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2079,7 +2079,10 @@ import transform.SymUtils._
20792079
case MethodNotAMethodMatch =>
20802080
"neither has parameters."
20812081
case FullMatch =>
2082-
i"have the same$nameAnd type after erasure."
2082+
i"""have the same$nameAnd type after erasure.
2083+
|
2084+
|Consider adding a @targetName annotation to one of the conflicting definitions
2085+
|for disambiguation."""
20832086
}
20842087
}
20852088
else ""

tests/neg/doubleDefinition.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
| def foo(x: List[A]): A => A in class Test2 at line 13 and
66
| def foo(x: List[B]): B => B in class Test2 at line 14
77
| have the same type after erasure.
8+
|
9+
| Consider adding a @targetName annotation to one of the conflicting definitions
10+
| for disambiguation.
811
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:21:4 ----------------------------------------------------------
912
21 | def foo(x: List[A]): Function2[B, B, B] = ??? // error
1013
| ^
@@ -43,6 +46,9 @@
4346
| def foo(x: List[A]): A => A in trait Test6 at line 54 and
4447
| def foo(x: List[B]): B => B in trait Test6 at line 55
4548
| have the same type after erasure.
49+
|
50+
| Consider adding a @targetName annotation to one of the conflicting definitions
51+
| for disambiguation.
4652
-- [E120] Naming Error: tests/neg/doubleDefinition.scala:62:4 ----------------------------------------------------------
4753
62 | def foo(x: List[A]): Function2[B, B, B] = ??? // error
4854
| ^

tests/neg/exports.check

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,29 @@
1919
| def status: => List[String] in class Copier at line 28 and
2020
| final def status: => List[String] in class Copier at line 23
2121
| have the same type after erasure.
22+
|
23+
| Consider adding a @targetName annotation to one of the conflicting definitions
24+
| for disambiguation.
2225
-- [E120] Naming Error: tests/neg/exports.scala:24:20 ------------------------------------------------------------------
2326
24 | export scanUnit._ // error: double definition
2427
| ^
2528
| Double definition:
2629
| final def status: => List[String] in class Copier at line 23 and
2730
| final def status: => List[String] in class Copier at line 24
2831
| have the same type after erasure.
32+
|
33+
| Consider adding a @targetName annotation to one of the conflicting definitions
34+
| for disambiguation.
2935
-- [E120] Naming Error: tests/neg/exports.scala:26:21 ------------------------------------------------------------------
3036
26 | export printUnit.status // error: double definition
3137
| ^
3238
| Double definition:
3339
| final def status: => List[String] in class Copier at line 24 and
3440
| final def status: => List[String] in class Copier at line 26
3541
| have the same type after erasure.
42+
|
43+
| Consider adding a @targetName annotation to one of the conflicting definitions
44+
| for disambiguation.
3645
-- Error: tests/neg/exports.scala:35:24 --------------------------------------------------------------------------------
3746
35 | export this.{concat => ++} // error: no eligible member
3847
| ^^^^^^^^^^^^

tests/neg/i7359-f.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
| 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.
8+
|
9+
| Consider adding a @targetName annotation to one of the conflicting definitions
10+
| for disambiguation.

tests/neg/mixin-forwarder-clash1.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
| def concat(suffix: Int): X in trait One at line 4 and
66
| def concat: [Dummy](suffix: Int): Y in trait Two at line 8
77
| have the same type after erasure.
8+
|
9+
| Consider adding a @targetName annotation to one of the conflicting definitions
10+
| for disambiguation.

tests/neg/mixin-forwarder-clash2.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
| def concat(suffix: Int): X in trait One at line 4 and
77
| def concat: [Dummy](suffix: Int): Y in trait Two at line 8
88
| have the same type after erasure.
9+
|
10+
| Consider adding a @targetName annotation to one of the conflicting definitions
11+
| for disambiguation.

tests/neg/override-erasure-clash.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
| def f(): Int in class A at line 3 and
66
| def g(): Int in class B at line 5
77
| have the same name and type after erasure.
8+
|
9+
| Consider adding a @targetName annotation to one of the conflicting definitions
10+
| for disambiguation.

0 commit comments

Comments
 (0)