Files
kotlin-fork/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.fir.kt
T
Jinseong Jeon e72ddbcbfe FIR checker: differentiate UNSAFE_CALL from INAPPLICABLE_CANDIDATE
To do so, inside the root cause of inapplicable candidate errors,
we will record expected/actual type of receiver, if any.
That will help identifying inapplicable calls on nullable receiver.
2021-01-29 16:54:23 +03:00

39 lines
823 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()) {
<!UNSAFE_CALL!>length<!>
}
else {
length
}
}
}
fun mixedReceiver(s: String?) {
if (!s.isNullOrEmpty()) {
with(s) {
length
}
} else {
with(s) {
<!UNSAFE_CALL!>length<!>
}
}
}