74c6d2b951
Previous changes related to this in the old JVM backend were in582b1c5e66and0482f7e9c5, but they did not affect the `ProperIeee754Comparisons` mode which became the default in 1.4.0. As a result, we had a regression here. Since the `PRIMITIVE_NUMERIC_COMPARISON_INFO` slice is used in psi2ir to determine how to generate the comparison, this fixes the regression both in the old JVM backend, and in all IR backends. #KT-41426 Fixed
59 lines
1.4 KiB
Kotlin
Vendored
59 lines
1.4 KiB
Kotlin
Vendored
// IGNORE_BACKEND_FIR: JVM_IR
|
|
|
|
var longCompareToInvocations = 0
|
|
var doubleCompareToInvocations = 0
|
|
|
|
private operator fun Long?.compareTo(other: Long?): Int {
|
|
longCompareToInvocations++
|
|
val diff = (this ?: 0L) - (other ?: 0L)
|
|
return when {
|
|
diff < 0L -> -1
|
|
diff > 0L -> 1
|
|
else -> 0
|
|
}
|
|
}
|
|
|
|
private operator fun Double?.compareTo(other: Double?): Int {
|
|
doubleCompareToInvocations++
|
|
val diff = (this ?: 0.0) - (other ?: 0.0)
|
|
return when {
|
|
diff < 0.0 -> -1
|
|
diff > 0.0 -> 1
|
|
else -> 0
|
|
}
|
|
}
|
|
|
|
fun checkLong(): String? {
|
|
val a: Long? = null
|
|
val b: Long? = 42L
|
|
|
|
if (a > b) return "Fail Long >"
|
|
if (a >= b) return "Fail Long >="
|
|
if (!(a < b)) return "Fail Long <"
|
|
if (!(a <= b)) return "Fail Long <="
|
|
|
|
if (longCompareToInvocations != 4) return "Fail: expected 4 compareTo invocations, but was $longCompareToInvocations"
|
|
|
|
return null
|
|
}
|
|
|
|
fun checkDouble(): String? {
|
|
val a: Double? = null
|
|
val b: Double? = 3.14
|
|
|
|
if (a > b) return "Fail Double >"
|
|
if (a >= b) return "Fail Double >="
|
|
if (!(a < b)) return "Fail Double <"
|
|
if (!(a <= b)) return "Fail Double <="
|
|
|
|
if (doubleCompareToInvocations != 4) return "Fail: expected 4 compareTo invocations, but was $doubleCompareToInvocations"
|
|
|
|
return null
|
|
}
|
|
|
|
fun box(): String {
|
|
checkLong()?.let { return it }
|
|
checkDouble()?.let { return it }
|
|
return "OK"
|
|
}
|