Skip to content

Commit a3cf20e

Browse files
committed
DoubleDefinition: Align description with Scala 2 errors
1 parent 9e82d56 commit a3cf20e

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ object messages {
21372137
val explanation: String = ""
21382138
}
21392139

2140-
case class DoubleDefinition(decl: Symbol, previousDecl: Symbol)(implicit ctx: Context) extends Message(DoubleDefinitionID) {
2140+
case class DoubleDefinition(decl: Symbol, previousDecl: Symbol, base: Symbol)(implicit ctx: Context) extends Message(DoubleDefinitionID) {
21412141
val kind: String = "Duplicate Symbol"
21422142
val msg: String = {
21432143
val details = if (decl.isRealMethod && previousDecl.isRealMethod) {
@@ -2157,9 +2157,17 @@ object messages {
21572157
s" at line ${sym.sourcePos.line + 1}" else ""
21582158
i"in ${sym.owner}${lineDesc}"
21592159
}
2160-
em"""Double definition:
2161-
|${previousDecl.initial.showDcl} ${symLocation(previousDecl)} and
2162-
|${decl.initial.showDcl} ${symLocation(decl)}
2160+
val clashDescription =
2161+
if (decl.owner eq previousDecl.owner)
2162+
"Double definition"
2163+
else if ((decl.owner eq base) || (previousDecl eq base))
2164+
"Name clash between defined and inherited member"
2165+
else
2166+
"Name clash between inherited members"
2167+
2168+
em"""$clashDescription:
2169+
|${previousDecl.showDcl} ${symLocation(previousDecl)} and
2170+
|${decl.showDcl} ${symLocation(decl)}
21632171
|""" + details
21642172
}
21652173
val explanation: String = ""

compiler/src/dotty/tools/dotc/transform/ElimErasedValueType.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class ElimErasedValueType extends MiniPhase with InfoTransformer {
104104
//
105105
// The problem is that `map` was forwarded twice, with different instantiated types.
106106
// Maybe we should move mixin forwarding after erasure to avoid redundant forwarders like these.
107-
ctx.error(DoubleDefinition(sym1, sym2), root.sourcePos)
107+
ctx.error(DoubleDefinition(sym1, sym2, root), root.sourcePos)
108108
}
109109
val earlyCtx = ctx.withPhase(ctx.elimRepeatedPhase.next)
110110
while (opc.hasNext) {

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ trait Checking {
755755
if (decl.matches(other) && !javaFieldMethodPair) {
756756
def doubleDefError(decl: Symbol, other: Symbol): Unit =
757757
if (!decl.info.isErroneous && !other.info.isErroneous)
758-
ctx.error(DoubleDefinition(decl, other), decl.sourcePos)
758+
ctx.error(DoubleDefinition(decl, other, cls), decl.sourcePos)
759759
if (decl is Synthetic) doubleDefError(other, decl)
760760
else doubleDefError(decl, other)
761761
}

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ class ErrorMessagesTests extends ErrorMessagesTest {
15141514
}.expect { (ictx, messages) =>
15151515
implicit val ctx: Context = ictx
15161516
assertMessageCount(1, messages)
1517-
val DoubleDefinition(symbol, previousSymbol) :: Nil = messages
1517+
val DoubleDefinition(symbol, previousSymbol, _) :: Nil = messages
15181518
assertEquals(symbol.name.mangledString, "a")
15191519
}
15201520

0 commit comments

Comments
 (0)