Fix incorrect diagnostic message for CONFLICTING_OVERLOADS
- the member and the container were mixed up - don't output "defined in" part of the message, because we tell later where it's already defined in - fix an instability of the diagnostic order in OverloadResolver by using LinkedHashSet
This commit is contained in:
+1
-1
@@ -398,7 +398,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(MANY_IMPL_MEMBER_NOT_IMPLEMENTED, "{0} must override {1} because it inherits many implementations of it",
|
||||
RENDER_CLASS_OR_OBJECT, DescriptorRenderer.TEXT);
|
||||
|
||||
MAP.put(CONFLICTING_OVERLOADS, "{1} is already defined in ''{0}''", DescriptorRenderer.TEXT, TO_STRING);
|
||||
MAP.put(CONFLICTING_OVERLOADS, "''{0}'' is already defined in {1}", DescriptorRenderer.COMPACT_WITH_MODIFIERS, TO_STRING);
|
||||
|
||||
MAP.put(FUNCTION_EXPECTED, "Expression ''{0}''{1} cannot be invoked as a function. The function 'invoke()' is not found", ELEMENT_TEXT, new Renderer<JetType>() {
|
||||
@NotNull
|
||||
|
||||
@@ -43,8 +43,6 @@ public class OverloadResolver {
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void process(@NotNull BodiesResolveContext c) {
|
||||
checkOverloads(c);
|
||||
}
|
||||
@@ -60,7 +58,7 @@ public class OverloadResolver {
|
||||
checkOverloadsInPackages(c, inPackages);
|
||||
}
|
||||
|
||||
private void fillGroupedConstructors(
|
||||
private static void fillGroupedConstructors(
|
||||
@NotNull BodiesResolveContext c,
|
||||
@NotNull MultiMap<ClassDescriptor, ConstructorDescriptor> inClasses,
|
||||
@NotNull MultiMap<FqNameUnsafe, ConstructorDescriptor> inPackages
|
||||
@@ -133,7 +131,7 @@ public class OverloadResolver {
|
||||
MultiMap<Name, CallableMemberDescriptor> functionsByName = MultiMap.create();
|
||||
|
||||
if (classDescriptor.getKind() == ClassKind.ENUM_CLASS) {
|
||||
ClassDescriptorWithResolutionScopes classObjectDescriptor = (ClassDescriptorWithResolutionScopes) classDescriptor.getClassObjectDescriptor();
|
||||
ClassDescriptorWithResolutionScopes classObjectDescriptor = classDescriptor.getClassObjectDescriptor();
|
||||
assert classObjectDescriptor != null;
|
||||
for (CallableMemberDescriptor memberDescriptor : classObjectDescriptor.getDeclaredCallableMembers()) {
|
||||
functionsByName.putValue(memberDescriptor.getName(), memberDescriptor);
|
||||
@@ -164,13 +162,12 @@ public class OverloadResolver {
|
||||
// micro-optimization
|
||||
return;
|
||||
}
|
||||
Set<Pair<JetDeclaration, CallableMemberDescriptor>> redeclarations = findRedeclarations(functions);
|
||||
reportRedeclarations(functionContainer, redeclarations);
|
||||
reportRedeclarations(functionContainer, findRedeclarations(functions));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Set<Pair<JetDeclaration, CallableMemberDescriptor>> findRedeclarations(@NotNull Collection<CallableMemberDescriptor> functions) {
|
||||
Set<Pair<JetDeclaration, CallableMemberDescriptor>> redeclarations = Sets.newHashSet();
|
||||
Set<Pair<JetDeclaration, CallableMemberDescriptor>> redeclarations = Sets.newLinkedHashSet();
|
||||
for (CallableMemberDescriptor member : functions) {
|
||||
for (CallableMemberDescriptor member2 : functions) {
|
||||
if (member == member2) {
|
||||
|
||||
@@ -60,6 +60,10 @@ public interface DescriptorRenderer extends Renderer<DeclarationDescriptor> {
|
||||
|
||||
DescriptorRenderer DEBUG_TEXT = new DescriptorRendererBuilder().setDebugMode(true).build();
|
||||
|
||||
DescriptorRenderer HTML_COMPACT_WITH_MODIFIERS = new DescriptorRendererBuilder()
|
||||
.setWithDefinedIn(false)
|
||||
.setTextFormat(TextFormat.HTML).build();
|
||||
|
||||
DescriptorRenderer HTML = new DescriptorRendererBuilder().setTextFormat(TextFormat.HTML).build();
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -17,7 +17,10 @@
|
||||
package org.jetbrains.jet.plugin.highlighter;
|
||||
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.DiagnosticFactoryToRendererMap;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.DiagnosticRenderer;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.DispatchingDiagnosticRenderer;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
@@ -82,7 +85,8 @@ public class IdeErrorMessages {
|
||||
|
||||
MAP.put(MANY_IMPL_MEMBER_NOT_IMPLEMENTED, "<html>{0} must override {1}<br />because it inherits many implementations of it</html>",
|
||||
RENDER_CLASS_OR_OBJECT, DescriptorRenderer.HTML);
|
||||
MAP.put(CONFLICTING_OVERLOADS, "<html>{1}<br />is already defined in ''{0}''</html>", DescriptorRenderer.HTML, TO_STRING);
|
||||
MAP.put(CONFLICTING_OVERLOADS, "<html>''{0}''<br />is already defined in {1}</html>",
|
||||
DescriptorRenderer.HTML_COMPACT_WITH_MODIFIERS, TO_STRING);
|
||||
|
||||
MAP.put(RESULT_TYPE_MISMATCH, "<html>Function return type mismatch." +
|
||||
"<table><tr><td>Expected:</td><td>{1}</td></tr>" +
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// !DIAGNOSTICS_NUMBER: 2
|
||||
// !DIAGNOSTICS: CONFLICTING_OVERLOADS
|
||||
|
||||
class conflictingOverloads {
|
||||
fun lol(x: Int) = x
|
||||
fun lol(y: Int) = y
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<!-- conflictingOverloadsClass1 -->
|
||||
<html>
|
||||
'<b>
|
||||
internal</b>
|
||||
<b>
|
||||
final</b>
|
||||
<b>
|
||||
fun</b>
|
||||
lol(x: kotlin.Int): kotlin.Int'<br />
|
||||
is already defined in conflictingOverloads</html>
|
||||
@@ -0,0 +1,10 @@
|
||||
<!-- conflictingOverloadsClass2 -->
|
||||
<html>
|
||||
'<b>
|
||||
internal</b>
|
||||
<b>
|
||||
final</b>
|
||||
<b>
|
||||
fun</b>
|
||||
lol(y: kotlin.Int): kotlin.Int'<br />
|
||||
is already defined in conflictingOverloads</html>
|
||||
@@ -36,6 +36,11 @@ public class DiagnosticMessageTestGenerated extends AbstractDiagnosticMessageTes
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/diagnosticMessage"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("conflictingOverloadsClass.kt")
|
||||
public void testConflictingOverloadsClass() throws Exception {
|
||||
doTest("idea/testData/diagnosticMessage/conflictingOverloadsClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("conflictingSubstitutions.kt")
|
||||
public void testConflictingSubstitutions() throws Exception {
|
||||
doTest("idea/testData/diagnosticMessage/conflictingSubstitutions.kt");
|
||||
|
||||
Reference in New Issue
Block a user