Files
kotlin-fork/compiler/testData/codegen/box/binaryOp/eqNullableToPrimitiveWithSideEffects.kt
T
pyos c3a91efea3 JVM_IR: fix primitive comparison optimizations
1. the `primitive == object?.something` fusion should not apply to
    `primitive.equals(object?.something)` because it can't;

 2. coercions to Int are there for a reason - don't remove them;

 3. better optimize `primitive == object?.something` -- the result
    should be subject to if-null fusion, so it needs to have a specific
    pattern that resembles safe calls.

 #KT-47597 Fixed
2021-07-05 18:13:09 +03:00

20 lines
390 B
Kotlin
Vendored

// IGNORE_BACKEND: JS, JS_IR, WASM, NATIVE
var result = ""
fun sideEffecting(): Int {
result += "OK"
return 123
}
class C(val x: Int)
val a: C? = C(123)
val b: C? = null
fun box(): String {
if (a?.x != sideEffecting()) return "fail cmp 1"
// RHS not evaluated because `b` is null, might be a bug:
if (b?.x == sideEffecting()) return "fail cmp 2"
return result
}