A warning added: parameter names disagree upon override
This should be an error, but there is an issue with Java interop: Java parameters may change names or not have them.
This commit is contained in:
@@ -383,6 +383,8 @@ public interface Errors {
|
||||
SimpleDiagnosticFactory<JetParameter> DEFAULT_VALUE_NOT_ALLOWED_IN_OVERRIDE = SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.PARAMETER_DEFAULT_VALUE);
|
||||
DiagnosticFactory1<JetParameter, ValueParameterDescriptor> MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES = DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||
DiagnosticFactory1<JetClassOrObject, ValueParameterDescriptor> MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES_WHEN_NO_EXPLICIT_OVERRIDE = DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||
DiagnosticFactory2<JetParameter, ClassDescriptor, ValueParameterDescriptor> PARAMETER_NAME_CHANGED_ON_OVERRIDE = DiagnosticFactory2.create(WARNING, PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||
DiagnosticFactory2<JetClassOrObject, Collection<? extends CallableMemberDescriptor>, Integer> DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES = DiagnosticFactory2.create(WARNING, PositioningStrategies.POSITION_NAME_IDENTIFIER);
|
||||
|
||||
DiagnosticFactory2<JetDeclaration, CallableMemberDescriptor, String> CONFLICTING_OVERLOADS =
|
||||
DiagnosticFactory2.create(ERROR, new PositioningStrategy<JetDeclaration>() {
|
||||
|
||||
+12
-4
@@ -386,11 +386,19 @@ public class DefaultErrorMessages {
|
||||
MAP.put(NOT_AN_ANNOTATION_CLASS, "''{0}'' is not an annotation class", TO_STRING);
|
||||
|
||||
MAP.put(DEFAULT_VALUE_NOT_ALLOWED_IN_OVERRIDE, "An overriding function is not allowed to specify default values for its parameters");
|
||||
MAP.put(MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES, "More than one overridden descriptor declares a default value for ''{0}''. " +
|
||||
"As the compiler can not make sure these values agree, this is not allowed.", TO_STRING);
|
||||
|
||||
MAP.put(MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES_WHEN_NO_EXPLICIT_OVERRIDE, "More than one overridden descriptor declares a default value for ''{0}''. " +
|
||||
"As the compiler can not make sure these values agree, this is not allowed.", TO_STRING);
|
||||
|
||||
String multipleDefaultsMessage = "More than one overridden descriptor declares a default value for ''{0}''. " +
|
||||
"As the compiler can not make sure these values agree, this is not allowed.";
|
||||
MAP.put(MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES, multipleDefaultsMessage, TO_STRING);
|
||||
MAP.put(MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES_WHEN_NO_EXPLICIT_OVERRIDE, multipleDefaultsMessage, TO_STRING);
|
||||
|
||||
MAP.put(PARAMETER_NAME_CHANGED_ON_OVERRIDE, "The corresponding parameter in the supertype ''{0}'' is named ''{1}''. " +
|
||||
"This may cause problems when calling this function with named arguments.", NAME, NAME);
|
||||
|
||||
MAP.put(DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES,
|
||||
"Names of the parameter #{1} conflict in the following members of supertypes: ''{0}''" +
|
||||
"This may cause problems when calling this function with named arguments.", commaSeparated(TO_STRING), TO_STRING);
|
||||
|
||||
MAP.setImmutable();
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
@@ -98,6 +99,24 @@ public class Renderers {
|
||||
}
|
||||
};
|
||||
|
||||
public static <T> Renderer<Collection<? extends T>> commaSeparated(final Renderer<T> itemRenderer) {
|
||||
return new Renderer<Collection<? extends T>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull Collection<? extends T> object) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Iterator<? extends T> iterator = object.iterator(); iterator.hasNext(); ) {
|
||||
T next = iterator.next();
|
||||
result.append(itemRenderer.render(next));
|
||||
if (iterator.hasNext()) {
|
||||
result.append(", ");
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Renderers() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,6 +437,9 @@ public class OverrideResolver {
|
||||
fakeOverride ? null :
|
||||
(JetParameter) BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), parameterFromSubclass);
|
||||
|
||||
JetClassOrObject classElement = fakeOverride ? (JetClassOrObject) BindingContextUtils
|
||||
.descriptorToDeclaration(trace.getBindingContext(), declared.getContainingDeclaration()) : null;
|
||||
|
||||
if (parameterFromSubclass.declaresDefaultValue() && !fakeOverride) {
|
||||
trace.report(DEFAULT_VALUE_NOT_ALLOWED_IN_OVERRIDE.on(parameter));
|
||||
}
|
||||
@@ -449,8 +452,6 @@ public class OverrideResolver {
|
||||
}
|
||||
else {
|
||||
if (fakeOverride) {
|
||||
JetClassOrObject classElement = (JetClassOrObject) BindingContextUtils
|
||||
.descriptorToDeclaration(trace.getBindingContext(), declared.getContainingDeclaration());
|
||||
trace.report(MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES_WHEN_NO_EXPLICIT_OVERRIDE.on(classElement, parameterFromSubclass));
|
||||
}
|
||||
else {
|
||||
@@ -459,6 +460,15 @@ public class OverrideResolver {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!parameterFromSuperclass.getName().equals(parameterFromSubclass.getName())) {
|
||||
if (fakeOverride) {
|
||||
trace.report(DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES.on(classElement, declared.getOverriddenDescriptors(), parameterFromSuperclass.getIndex() + 1));
|
||||
}
|
||||
else {
|
||||
trace.report(PARAMETER_NAME_CHANGED_ON_OVERRIDE.on(parameter, (ClassDescriptor) parameterFromSuperclass.getContainingDeclaration().getContainingDeclaration(), parameterFromSuperclass));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user