Fix data class hashcode generation
It considers Boolean hashCode equal to 1/0 for true/false, which is different from actual hashCode of the Boolean type.
This commit is contained in:
committed by
Space Team
parent
36924775c8
commit
fd4d4f516f
@@ -588,14 +588,6 @@ public class DescriptorAsmUtil {
|
|||||||
else if (type.getSort() == Type.OBJECT) {
|
else if (type.getSort() == Type.OBJECT) {
|
||||||
iv.invokevirtual("java/lang/Object", "hashCode", "()I", false);
|
iv.invokevirtual("java/lang/Object", "hashCode", "()I", false);
|
||||||
}
|
}
|
||||||
else if (type.getSort() == Type.BOOLEAN) {
|
|
||||||
Label end = new Label();
|
|
||||||
iv.dup();
|
|
||||||
iv.ifeq(end);
|
|
||||||
iv.pop();
|
|
||||||
iv.iconst(1);
|
|
||||||
iv.mark(end);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
HashCode.Companion.invokeHashCode(iv, type);
|
HashCode.Companion.invokeHashCode(iv, type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
data class A(val a: Boolean)
|
data class A(val a: Boolean)
|
||||||
|
|
||||||
fun box() : String {
|
fun box() : String {
|
||||||
if (A(true).hashCode() != 1) return "fail1"
|
if (A(true).hashCode() != 1231) return "fail1"
|
||||||
if (A(false).hashCode() !=0) return "fail2"
|
if (A(false).hashCode() != 1237) return "fail2"
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ data class Hash(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// 8 \.hashCode
|
// 9 \.hashCode
|
||||||
// 0 INVOKESTATIC java/lang/Boolean\.hashCode \(Z\)I
|
// 1 INVOKESTATIC java/lang/Boolean\.hashCode \(Z\)I
|
||||||
// 1 INVOKESTATIC java/lang/Byte\.hashCode \(B\)I
|
// 1 INVOKESTATIC java/lang/Byte\.hashCode \(B\)I
|
||||||
// 1 INVOKESTATIC java/lang/Character\.hashCode \(C\)I
|
// 1 INVOKESTATIC java/lang/Character\.hashCode \(C\)I
|
||||||
// 1 INVOKESTATIC java/lang/Short\.hashCode \(S\)I
|
// 1 INVOKESTATIC java/lang/Short\.hashCode \(S\)I
|
||||||
|
|||||||
Reference in New Issue
Block a user