2ecba6ac39
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)
36 lines
743 B
Kotlin
Vendored
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()
|
|
}
|
|
}
|
|
}
|
|
|