diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index e4ba109ceaa..a847342af33 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -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(); diff --git a/compiler/testData/codegen/dataClasses/hashcode/genericNull.kt b/compiler/testData/codegen/dataClasses/hashcode/genericNull.kt new file mode 100644 index 00000000000..6987eab9670 --- /dev/null +++ b/compiler/testData/codegen/dataClasses/hashcode/genericNull.kt @@ -0,0 +1,7 @@ +data class A(val t: T) + +fun box(): String { + val h = A(null).hashCode() + if (h != 0) return "Fail $h" + return "OK" +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/DataClassCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/DataClassCodegenTestGenerated.java index 11f8ddb5238..ce8c33e95e5 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/DataClassCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/DataClassCodegenTestGenerated.java @@ -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");