Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/savedSmartcastResult.kt
T
Aleksandra.Arsenteva c6b32200df [Test] Add diagnostic tests for smartcast in K2
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
2023-12-18 13:08:33 +00:00

35 lines
815 B
Kotlin
Vendored

// ISSUE: KT-25747
fun test1() {
val nullableString: String? = ""
val savedSmartCastResult = nullableString != null
if (savedSmartCastResult) {
nullableString<!UNSAFE_CALL!>.<!>length
}
}
fun test2() {
var nullableAny: Any? = ""
val savedSmartCastResult = nullableAny is String
nullableAny = 10
if (savedSmartCastResult) {
nullableAny.<!UNRESOLVED_REFERENCE!>length<!>
}
}
class A {
val a: String? = ""
}
fun test3(a: A){
val savedSmartCastResult = a.a != null
if(savedSmartCastResult) {
a.a<!UNSAFE_CALL!>.<!>length
}
}
fun test4() {
val nullableAny: Any? = ""
val savedSmartCastResult = (nullableAny!= null && nullableAny is String?)
if(savedSmartCastResult) {
nullableAny.<!UNRESOLVED_REFERENCE!>length<!>
}
}