ee8702d21e
See changes in e2606b72bdbec2fea567d4127197707869eb801e
37 lines
766 B
Kotlin
Vendored
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()
|
|
}
|
|
}
|
|
}
|
|
|