Files
kotlin-fork/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/receiver.fir.kt
T
2020-04-15 11:13:01 +03:00

37 lines
724 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.<!AMBIGUITY!>inc<!>()
}
else {
x.dec()
}
}
class UnstableReceiver {
var x: Int? = 42
fun smartcastOnUnstableReceiver() {
if (x.isNull()) {
x.<!AMBIGUITY!>inc<!>()
}
else {
x.<!AMBIGUITY!>dec<!>()
}
}
}