c6b32200df
List of issues: KT-28806, KT-7186, KT-22997, KT-1982, KT-22996, KT-54443, KT-37308, KT-37115, KT-4113, KT-25747, KT-24779
55 lines
1.1 KiB
Kotlin
Vendored
55 lines
1.1 KiB
Kotlin
Vendored
// ISSUE: KT-37308
|
|
// WITH_STDLIB
|
|
// DIAGNOSTICS: -ERROR_SUPPRESSION
|
|
import kotlin.contracts.*
|
|
|
|
@OptIn(ExperimentalContracts::class)
|
|
fun CharSequence?.valueIsNotNull(): Boolean {
|
|
contract {
|
|
returns(true) implies (this@valueIsNotNull != null)
|
|
}
|
|
return this != null
|
|
}
|
|
@OptIn(ExperimentalContracts::class)
|
|
fun CharSequence?.valueIsNull(): Boolean {
|
|
contract {
|
|
returns(false) implies (this@valueIsNull != null)
|
|
}
|
|
return this == null
|
|
}
|
|
|
|
class A {
|
|
val b: String? = ""
|
|
val e: C? = C()
|
|
}
|
|
|
|
class C {
|
|
val d: String? = ""
|
|
}
|
|
|
|
fun test1(a: A?) {
|
|
if (!a?.b.valueIsNull()) {
|
|
a<!UNSAFE_CALL!>.<!>b<!UNSAFE_CALL!>.<!>length
|
|
}
|
|
}
|
|
|
|
fun test2(a: A?) {
|
|
require(!a?.b.valueIsNull())
|
|
a<!UNSAFE_CALL!>.<!>b<!UNSAFE_CALL!>.<!>length
|
|
}
|
|
|
|
fun test3(a: A?) {
|
|
if(a?.b.valueIsNotNull()){
|
|
a<!UNSAFE_CALL!>.<!>b<!UNSAFE_CALL!>.<!>length
|
|
}
|
|
}
|
|
|
|
fun test4(a :A?) {
|
|
require(a?.b.valueIsNotNull())
|
|
a<!UNSAFE_CALL!>.<!>b<!UNSAFE_CALL!>.<!>length
|
|
}
|
|
|
|
fun test5(a :A?) {
|
|
require(a?.e?.d.valueIsNotNull())
|
|
a<!UNSAFE_CALL!>.<!>e<!UNSAFE_CALL!>.<!>d<!UNSAFE_CALL!>.<!>length
|
|
} |