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:
@@ -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.ImplicitReceiver;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
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.FieldVisitor;
|
||||||
import org.jetbrains.org.objectweb.asm.Label;
|
import org.jetbrains.org.objectweb.asm.Label;
|
||||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||||
@@ -577,7 +578,13 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
if (isPrimitive(asmType)) {
|
if (isPrimitive(asmType)) {
|
||||||
StackValue value = StackValue.cmp(KtTokens.EQEQ, asmType, StackValue.onStack(asmType), StackValue.onStack(asmType));
|
StackValue value = StackValue.cmp(KtTokens.EQEQ, asmType, StackValue.onStack(asmType), StackValue.onStack(asmType));
|
||||||
value.put(Type.BOOLEAN_TYPE, iv);
|
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 =
|
Type owner =
|
||||||
DescriptorUtils.isInterface(propertyDescriptor.getType().getConstructor().getDeclarationDescriptor())
|
DescriptorUtils.isInterface(propertyDescriptor.getType().getConstructor().getDeclarationDescriptor())
|
||||||
? AsmTypes.OBJECT_TYPE
|
? AsmTypes.OBJECT_TYPE
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
data class A(val v: Any?)
|
||||||
|
|
||||||
|
data class B<T>(val v: T)
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a1 = A(null)
|
||||||
|
val a2 = A("")
|
||||||
|
if (a1 == a2 || a2 == a1) return "Fail 1"
|
||||||
|
|
||||||
|
val b1 = B(null)
|
||||||
|
val b2 = B("")
|
||||||
|
if (b1 == b2 || b2 == b1) return "Fail 2"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Generated
+6
@@ -7230,6 +7230,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("null.kt")
|
||||||
|
public void testNull() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/equals/null.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nullother.kt")
|
@TestMetadata("nullother.kt")
|
||||||
public void testNullother() throws Exception {
|
public void testNullother() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/equals/nullother.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/equals/nullother.kt");
|
||||||
|
|||||||
+6
@@ -7230,6 +7230,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("null.kt")
|
||||||
|
public void testNull() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/equals/null.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nullother.kt")
|
@TestMetadata("nullother.kt")
|
||||||
public void testNullother() throws Exception {
|
public void testNullother() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/equals/nullother.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/equals/nullother.kt");
|
||||||
|
|||||||
+6
@@ -7230,6 +7230,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("null.kt")
|
||||||
|
public void testNull() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/equals/null.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nullother.kt")
|
@TestMetadata("nullother.kt")
|
||||||
public void testNullother() throws Exception {
|
public void testNullother() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/equals/nullother.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/equals/nullother.kt");
|
||||||
|
|||||||
+6
@@ -8563,6 +8563,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("null.kt")
|
||||||
|
public void testNull() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/equals/null.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nullother.kt")
|
@TestMetadata("nullother.kt")
|
||||||
public void testNullother() throws Exception {
|
public void testNullother() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/equals/nullother.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/dataClasses/equals/nullother.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user