Fix constructors redeclaration message

#KT-6966 Fixed
This commit is contained in:
Denis Zharkov
2015-03-12 21:19:47 +03:00
parent 22425de5cb
commit 6c46606f2b
8 changed files with 41 additions and 1 deletions
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.JetClassOrObject;
import org.jetbrains.kotlin.psi.JetDeclaration;
import org.jetbrains.kotlin.psi.JetObjectDeclaration;
import org.jetbrains.kotlin.psi.JetSecondaryConstructor;
import javax.inject.Inject;
import java.util.Collection;
@@ -201,7 +202,12 @@ public class OverloadResolver {
trace.report(Errors.REDECLARATION.on(jetDeclaration, memberDescriptor.getName().asString()));
}
else {
trace.report(Errors.CONFLICTING_OVERLOADS.on(jetDeclaration, memberDescriptor, functionContainer));
String containingClassName = jetDeclaration instanceof JetSecondaryConstructor ?
((JetSecondaryConstructor) jetDeclaration).getClassOrObject().getName() : null;
trace.report(Errors.CONFLICTING_OVERLOADS.on(
jetDeclaration, memberDescriptor,
containingClassName != null ? containingClassName : functionContainer));
}
}
}
@@ -0,0 +1,7 @@
// !DIAGNOSTICS_NUMBER: 2
// !DIAGNOSTICS: CONFLICTING_OVERLOADS
// !MESSAGE_TYPE: TEXT
class Element {
constructor(x : String) {}
constructor(x : String) {}
}
@@ -0,0 +1,2 @@
<!-- constructorsRedeclaration1 -->
'public constructor Element(x: kotlin.String)' is already defined in Element
@@ -0,0 +1,2 @@
<!-- constructorsRedeclaration2 -->
'public constructor Element(x: kotlin.String)' is already defined in Element
@@ -0,0 +1,7 @@
// !DIAGNOSTICS_NUMBER: 2
// !DIAGNOSTICS: CONFLICTING_OVERLOADS
// !MESSAGE_TYPE: TEXT
fun Element(x: String) {}
class Element {
constructor(x : String) {}
}
@@ -0,0 +1,2 @@
<!-- constructorsRedeclarationTopLevel1 -->
'internal fun Element(x: kotlin.String): kotlin.Unit' is already defined in root package
@@ -0,0 +1,2 @@
<!-- constructorsRedeclarationTopLevel2 -->
'public constructor Element(x: kotlin.String)' is already defined in Element
@@ -72,6 +72,18 @@ public class DiagnosticMessageTestGenerated extends AbstractDiagnosticMessageTes
doTest(fileName);
}
@TestMetadata("constructorsRedeclaration.kt")
public void testConstructorsRedeclaration() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/diagnosticMessage/constructorsRedeclaration.kt");
doTest(fileName);
}
@TestMetadata("constructorsRedeclarationTopLevel.kt")
public void testConstructorsRedeclarationTopLevel() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/diagnosticMessage/constructorsRedeclarationTopLevel.kt");
doTest(fileName);
}
@TestMetadata("differentNamesForSameParameter.kt")
public void testDifferentNamesForSameParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/diagnosticMessage/differentNamesForSameParameter.kt");