[JVM IR] Use reference equality when comparing enums.

This commit is contained in:
Mark Punzalan
2020-03-06 01:35:05 -08:00
committed by Alexander Udalov
parent a732e8f5fe
commit 368b0d9b0b
14 changed files with 82 additions and 7 deletions
+2 -4
View File
@@ -1,6 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// TODO KT-36772 Equality compaison between enums should use reference equality in JVM_IR
enum class Bar {
ONE,
TWO
@@ -9,11 +6,12 @@ enum class Bar {
fun isOne(i: Bar) = i == Bar.ONE
fun box(): String {
return when (isOne(Bar.ONE) && !isOne(Bar.TWO)) {
return when (isOne(Bar.ONE) && !isOne(Bar.TWO) && Bar.ONE != Bar.TWO) {
true -> "OK"
else -> "Failure"
}
}
// 1 IF_ACMPNE
// 1 IF_ACMPEQ
// 0 INVOKESTATIC kotlin/jvm/internal/Intrinsics.areEqual \(Ljava/lang/Object;Ljava/lang/Object;\)Z
@@ -0,0 +1,16 @@
enum class Bar {
ONE {
override fun toString(): String {
if (this != TWO && this == ONE) return "OK" else return "FAIL"
}
},
TWO;
}
fun box(): String {
return Bar.ONE.toString()
}
// 1 IF_ACMPNE
// 1 IF_ACMPEQ
// 0 INVOKESTATIC kotlin/jvm/internal/Intrinsics.areEqual \(Ljava/lang/Object;Ljava/lang/Object;\)Z