Fix NPE in data class 'equals' codegen

Do not perform the optimization from 0a11385006 for data class
properties of nullable types
This commit is contained in:
Alexander Udalov
2018-04-12 19:47:49 +02:00
parent 579b773388
commit 30b9caeae6
6 changed files with 47 additions and 1 deletions
@@ -52,6 +52,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.TypeUtils;
import org.jetbrains.org.objectweb.asm.FieldVisitor;
import org.jetbrains.org.objectweb.asm.Label;
import org.jetbrains.org.objectweb.asm.MethodVisitor;
@@ -577,7 +578,13 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (isPrimitive(asmType)) {
StackValue value = StackValue.cmp(KtTokens.EQEQ, asmType, StackValue.onStack(asmType), StackValue.onStack(asmType));
value.put(Type.BOOLEAN_TYPE, iv);
} else {
}
else if (TypeUtils.isNullableType(propertyDescriptor.getType())) {
StackValue value =
genEqualsForExpressionsOnStack(KtTokens.EQEQ, StackValue.onStack(asmType), StackValue.onStack(asmType));
value.put(Type.BOOLEAN_TYPE, iv);
}
else {
Type owner =
DescriptorUtils.isInterface(propertyDescriptor.getType().getConstructor().getDeclarationDescriptor())
? AsmTypes.OBJECT_TYPE