Fix generic data class hashCode for null
Null may come from everywhere, so we always check for it (when the property's type is not primitive)
This commit is contained in:
@@ -506,14 +506,14 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
genPropertyOnStack(iv, propertyDescriptor, 0);
|
||||
|
||||
Label ifNull = null;
|
||||
if (propertyDescriptor.getType().isNullable()) {
|
||||
Type asmType = typeMapper.mapType(propertyDescriptor.getType());
|
||||
if (!isPrimitive(asmType)) {
|
||||
ifNull = new Label();
|
||||
|
||||
iv.dup();
|
||||
iv.ifnull(ifNull);
|
||||
}
|
||||
|
||||
genHashCode(mv, iv, typeMapper.mapType(propertyDescriptor.getType()));
|
||||
genHashCode(mv, iv, asmType);
|
||||
|
||||
if (ifNull != null) {
|
||||
Label end = new Label();
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
data class A<T>(val t: T)
|
||||
|
||||
fun box(): String {
|
||||
val h = A<String?>(null).hashCode()
|
||||
if (h != 0) return "Fail $h"
|
||||
return "OK"
|
||||
}
|
||||
@@ -223,6 +223,11 @@ public class DataClassCodegenTestGenerated extends AbstractDataClassCodegenTest
|
||||
blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/hashcode/float.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericNull.kt")
|
||||
public void testGenericNull() throws Exception {
|
||||
blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/hashcode/genericNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("int.kt")
|
||||
public void testInt() throws Exception {
|
||||
blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/hashcode/int.kt");
|
||||
|
||||
Reference in New Issue
Block a user