Fix bytecode for equals/hashCode of data classes once again
#KT-24790 Fixed
This commit is contained in:
@@ -36,7 +36,6 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.InlineClassesUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil;
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes;
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName;
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType;
|
||||
import org.jetbrains.kotlin.resolve.jvm.RuntimeAssertionInfo;
|
||||
@@ -514,7 +513,7 @@ public class AsmUtil {
|
||||
});
|
||||
}
|
||||
|
||||
static void genHashCode(MethodVisitor mv, InstructionAdapter iv, Type type, JvmTarget jvmTarget, boolean isInterface) {
|
||||
static void genHashCode(MethodVisitor mv, InstructionAdapter iv, Type type, JvmTarget jvmTarget) {
|
||||
if (type.getSort() == Type.ARRAY) {
|
||||
Type elementType = correctElementType(type);
|
||||
if (elementType.getSort() == Type.OBJECT || elementType.getSort() == Type.ARRAY) {
|
||||
@@ -525,7 +524,7 @@ public class AsmUtil {
|
||||
}
|
||||
}
|
||||
else if (type.getSort() == Type.OBJECT) {
|
||||
iv.invokevirtual((isInterface ? AsmTypes.OBJECT_TYPE : type).getInternalName(), "hashCode", "()I", false);
|
||||
iv.invokevirtual(type.getInternalName(), "hashCode", "()I", false);
|
||||
}
|
||||
else if (type.getSort() == Type.BOOLEAN) {
|
||||
Label end = new Label();
|
||||
|
||||
@@ -558,8 +558,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
iv.store(2, OBJECT_TYPE);
|
||||
|
||||
for (PropertyDescriptor propertyDescriptor : properties) {
|
||||
KotlinType type = propertyDescriptor.getType();
|
||||
Type asmType = typeMapper.mapType(type);
|
||||
Type asmType = typeMapper.mapType(propertyDescriptor);
|
||||
|
||||
Type thisPropertyType = genPropertyOnStack(iv, context, propertyDescriptor, ImplementationBodyCodegen.this.classAsmType, 0);
|
||||
StackValue.coerce(thisPropertyType, asmType, iv);
|
||||
@@ -581,19 +580,16 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
value.put(Type.BOOLEAN_TYPE, iv);
|
||||
}
|
||||
else {
|
||||
if (TypeUtils.isNullableType(type)) {
|
||||
if (TypeUtils.isNullableType(propertyDescriptor.getType())) {
|
||||
StackValue value =
|
||||
genEqualsForExpressionsOnStack(KtTokens.EQEQ, StackValue.onStack(asmType), StackValue.onStack(asmType));
|
||||
value.put(Type.BOOLEAN_TYPE, iv);
|
||||
}
|
||||
else {
|
||||
ClassifierDescriptor classifier = type.getConstructor().getDeclarationDescriptor();
|
||||
Type owner =
|
||||
!(classifier instanceof ClassDescriptor) || DescriptorUtils.isInterface(classifier)
|
||||
? AsmTypes.OBJECT_TYPE
|
||||
: asmType;
|
||||
iv.invokevirtual(owner.getInternalName(), "equals",
|
||||
Type.getMethodDescriptor(Type.BOOLEAN_TYPE, AsmTypes.OBJECT_TYPE), false);
|
||||
iv.invokevirtual(
|
||||
getEqualsOrHashCodeOwner(propertyDescriptor).getInternalName(), "equals",
|
||||
Type.getMethodDescriptor(Type.BOOLEAN_TYPE, AsmTypes.OBJECT_TYPE), false
|
||||
);
|
||||
}
|
||||
}
|
||||
iv.ifeq(ne);
|
||||
@@ -636,8 +632,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
iv.ifnull(ifNull);
|
||||
}
|
||||
|
||||
genHashCode(mv, iv, asmType, state.getTarget(),
|
||||
DescriptorUtils.isInterface(propertyDescriptor.getType().getConstructor().getDeclarationDescriptor()));
|
||||
genHashCode(mv, iv, getEqualsOrHashCodeOwner(propertyDescriptor), state.getTarget());
|
||||
|
||||
if (ifNull != null) {
|
||||
Label end = new Label();
|
||||
@@ -661,6 +656,14 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
FunctionCodegen.endVisit(mv, "hashCode", myClass);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Type getEqualsOrHashCodeOwner(@NotNull PropertyDescriptor descriptor) {
|
||||
ClassifierDescriptor classifier = descriptor.getType().getConstructor().getDeclarationDescriptor();
|
||||
return !(classifier instanceof ClassDescriptor) || JvmCodegenUtil.isJvmInterface(classifier)
|
||||
? AsmTypes.OBJECT_TYPE
|
||||
: typeMapper.mapType(descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateToStringMethod(@NotNull FunctionDescriptor function, @NotNull List<? extends PropertyDescriptor> properties) {
|
||||
MethodContext context = ImplementationBodyCodegen.this.context.intoFunction(function);
|
||||
|
||||
Reference in New Issue
Block a user