File tree Expand file tree Collapse file tree 4 files changed +25
-5
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 4 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ public enum ErrorMessageID {
127
127
PolymorphicMethodMissingTypeInParentID ,
128
128
ParamsNoInlineID ,
129
129
JavaSymbolIsNotAValueID ,
130
+ DoubleDeclarationID ,
130
131
;
131
132
132
133
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -2079,4 +2079,10 @@ object messages {
2079
2079
}
2080
2080
val explanation = " "
2081
2081
}
2082
+
2083
+ case class DoubleDeclaration (decl : Symbol , previousSymbol : Symbol )(implicit ctx : Context ) extends Message (DoubleDeclarationID ) {
2084
+ val kind = " Duplicate Symbol"
2085
+ val msg = hl " $decl is already defined as $previousSymbol${previousSymbol.showExtendedLocation}"
2086
+ val explanation = " "
2087
+ }
2082
2088
}
Original file line number Diff line number Diff line change @@ -627,7 +627,7 @@ trait Checking {
627
627
def explanation =
628
628
if (! decl.isRealMethod) " "
629
629
else " \n (the definitions have matching type signatures)"
630
- ctx.error(em " $ decl is already defined as $ other$ofType$explanation " , decl.pos)
630
+ ctx.error(DoubleDeclaration ( decl, other) , decl.pos)
631
631
}
632
632
if (decl is Synthetic ) doubleDefError(other, decl)
633
633
else doubleDefError(decl, other)
Original file line number Diff line number Diff line change @@ -2,12 +2,10 @@ package dotty.tools
2
2
package dotc
3
3
package reporting
4
4
5
- import core .Contexts .Context
6
- import diagnostic .messages ._
7
- import dotty .tools .dotc .core .Flags
8
- import dotty .tools .dotc .core .Flags .FlagSet
5
+ import dotty .tools .dotc .core .Contexts .Context
9
6
import dotty .tools .dotc .core .Types .WildcardType
10
7
import dotty .tools .dotc .parsing .Tokens
8
+ import dotty .tools .dotc .reporting .diagnostic .messages ._
11
9
import org .junit .Assert ._
12
10
import org .junit .Test
13
11
@@ -1293,4 +1291,19 @@ class ErrorMessagesTests extends ErrorMessagesTest {
1293
1291
1294
1292
assert(ctx.reporter.hasErrors)
1295
1293
}
1294
+
1295
+ @ Test def typeDoubleDeclaration =
1296
+ checkMessagesAfter(" frontend" ) {
1297
+ """
1298
+ |class Foo {
1299
+ | val a = 1
1300
+ | val a = 2
1301
+ |}
1302
+ """ .stripMargin
1303
+ }.expect { (ictx, messages) =>
1304
+ implicit val ctx : Context = ictx
1305
+ assertMessageCount(1 , messages)
1306
+ val DoubleDeclaration (symbol, previousSymbol) :: Nil = messages
1307
+ assertEquals(symbol.name.mangledString, " a" )
1308
+ }
1296
1309
}
You can’t perform that action at this time.
0 commit comments