Files
kotlin-fork/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/receiver.kt
T
Dmitry Savvinov ee8702d21e Load of testdata change due to contracts publishing
See changes in e2606b72bdbec2fea567d4127197707869eb801e
2018-08-30 16:19:55 +03:00

37 lines
766 B
Kotlin
Vendored

// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
// !WITH_NEW_INFERENCE
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()
}
}
}