File tree 2 files changed +37
-1
lines changed
compiler/src/dotty/tools/dotc/reporting/diagnostic 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -2082,7 +2082,14 @@ object messages {
2082
2082
2083
2083
case class DoubleDeclaration (decl : Symbol , previousSymbol : Symbol )(implicit ctx : Context ) extends Message (DoubleDeclarationID ) {
2084
2084
val kind = " Duplicate Symbol"
2085
- val msg = hl " $decl is already defined as $previousSymbol${previousSymbol.showExtendedLocation}"
2085
+ val msg = {
2086
+ val details = decl.asTerm.signature.matchDegree(previousSymbol.asTerm.signature) match {
2087
+ case Signature .NoMatch => " " // matchDegree also returns NoMatch if one of the terms is not a method
2088
+ case Signature .ParamMatch => " \n Overloads with equal parameter types but different return types are not allowed."
2089
+ case Signature .FullMatch => " \n The definitions have the same signature after erasure."
2090
+ }
2091
+ hl " ${decl.showLocated} is already defined as ${previousSymbol.showDcl} in line ${previousSymbol.pos.line}. " + details
2092
+ }
2086
2093
val explanation = " "
2087
2094
}
2088
2095
}
Original file line number Diff line number Diff line change
1
+ trait A
2
+ trait B
3
+
4
+ class Test1 {
5
+ def foo (x : List [A ]): Function1 [A , A ] = ???
6
+ def foo (x : List [B ]): Function2 [B , B , B ] = ???
7
+ // ok, different jvm signature
8
+ }
9
+
10
+
11
+ class Test2 {
12
+
13
+
14
+
15
+ def foo (
16
+ x : List [A ]
17
+ ): Function1 [A ,
18
+ A ] =
19
+ ???
20
+ def foo (x : List [B ]): Function1 [B , B ] = ??? // error: same jvm signature
21
+ // scalac calls this "have same type after erasure"
22
+ }
23
+
24
+
25
+ class Test3 {
26
+ // overload with same argument type, but different return types
27
+ def foo (x : List [A ]): Function1 [A , A ] = ???
28
+ def foo (x : List [A ]): Function2 [B , B , B ] = ??? // error
29
+ }
You can’t perform that action at this time.
0 commit comments