Files
kotlin-fork/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/receiver.kt
T
Denis.Zharkov 2ecba6ac39 Remove WITH_NEW_INFERENCE directive from all tests
This directive anyway does not make test run twice with OI, and with NI
It only once run the test with specific settings (// LANGUAGE)
and ignores irrelevant (OI or NI tags)
2021-05-25 13:28:26 +03:00

36 lines
743 B
Kotlin
Vendored

// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.contracts.*
fun Any?.isNull(): Boolean {
contract {
returns(false) implies (this@isNull != null)
}
return this == null
}
fun smartcastOnReceiver(x: Int?) {
if (x.isNull()) {
x<!UNSAFE_CALL!>.<!>inc()
}
else {
<!DEBUG_INFO_SMARTCAST!>x<!>.dec()
}
}
class UnstableReceiver {
var x: Int? = 42
fun smartcastOnUnstableReceiver() {
if (x.isNull()) {
x<!UNSAFE_CALL!>.<!>inc()
}
else {
<!SMARTCAST_IMPOSSIBLE!>x<!>.dec()
}
}
}