Files
kotlin-fork/compiler/testData/codegen/box/boxingOptimization/safeCallWithElvis.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

30 lines
545 B
Kotlin
Vendored

// WITH_STDLIB
import kotlin.test.assertEquals
class A(val x : Int, val y : A?)
fun check(a : A?) : Int {
return a?.y?.x ?: (a?.x ?: 3)
}
fun checkLeftAssoc(a : A?) : Int {
return (a?.y?.x ?: a?.x) ?: 3
}
fun box() : String {
val a1 = A(2, A(1, null))
val a2 = A(2, null)
val a3 = null
assertEquals(1, check(a1))
assertEquals(2, check(a2))
assertEquals(3, check(a3))
assertEquals(1, checkLeftAssoc(a1))
assertEquals(2, checkLeftAssoc(a2))
assertEquals(3, checkLeftAssoc(a3))
return "OK"
}