Files
kotlin-fork/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.fir.kt
T
Denis Zharkov f97cc0b62d FIR: Rework receivers processing in resolution
- Put extensionReceiver to candidate even if it's explicit (for sake of clarity)
- Split CheckReceiver (dispatch part should only check nullability)
2020-11-16 15:50:39 +03:00

39 lines
845 B
Kotlin
Vendored

// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect -ContractsOnCallsWithImplicitReceiver
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
//
// ISSUE: KT-28672
import kotlin.contracts.*
fun CharSequence?.isNullOrEmpty(): Boolean {
contract {
returns(false) implies (this@isNullOrEmpty != null)
}
return this == null || this.length == 0
}
fun smartcastOnReceiver(s: String?) {
with(s) {
if (isNullOrEmpty()) {
<!INAPPLICABLE_CANDIDATE!>length<!>
}
else {
length
}
}
}
fun mixedReceiver(s: String?) {
if (!s.isNullOrEmpty()) {
with(s) {
length
}
} else {
with(s) {
<!INAPPLICABLE_CANDIDATE!>length<!>
}
}
}