Suppress "nothing to override" on equals, hashCode, toString
This is needed to smoothly make equals, hashCode and toString members of Any instead of being extensions, as they are now: according to our bootstrapping process, the same compiler code will be built twice, by old compiler (with extensions) and by new compiler (with members). In the resulting code 'override' should be on all these members in all classes, so the old compiler should be able to compile such code
This commit is contained in:
@@ -565,12 +565,34 @@ public class OverrideResolver {
|
||||
if (invisibleOverriddenDescriptor != null) {
|
||||
reportError.cannotOverrideInvisibleMember(invisibleOverriddenDescriptor);
|
||||
}
|
||||
else {
|
||||
else if (!shouldSuppressOverride(declared)) {
|
||||
reportError.nothingToOverride();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: this is temporary to migrate equals, hashCode, toString from extensions to Any
|
||||
private static boolean shouldSuppressOverride(@NotNull CallableMemberDescriptor descriptor) {
|
||||
String name = descriptor.getName().asString();
|
||||
JetType returnType = descriptor.getReturnType();
|
||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||
|
||||
if (name.equals("equals") && builtIns.getBooleanType().equals(returnType)) {
|
||||
List<ValueParameterDescriptor> parameters = descriptor.getValueParameters();
|
||||
return parameters.size() == 1 && builtIns.isAnyOrNullableAny(parameters.iterator().next().getType());
|
||||
}
|
||||
|
||||
if (name.equals("hashCode") && builtIns.getIntType().equals(returnType)) {
|
||||
return descriptor.getValueParameters().isEmpty();
|
||||
}
|
||||
|
||||
if (name.equals("toString") && builtIns.getStringType().equals(returnType)) {
|
||||
return descriptor.getValueParameters().isEmpty();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void checkOverrideForComponentFunction(@NotNull final CallableMemberDescriptor componentFunction) {
|
||||
final JetAnnotationEntry dataAnnotation = findDataAnnotationForDataClass(componentFunction.getContainingDeclaration());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user