Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/kt30927.kt
T
Ilya Chernikov 6356807997 Reapply "Only create descriptors for candidates with lambda args"
#KT-36247 fixed
A lot of testdata changed because significanly less (error) descriptors
are created for unresolved types, so diagnostics became different.
2020-02-14 11:41:30 +01:00

51 lines
1.5 KiB
Kotlin
Vendored

// !DIAGNOSTICS: -UNUSED_EXPRESSION
// !WITH_NEW_INFERENCE
// !CHECK_TYPE
fun case_0() {
val z: Any? = 10
val y = z.run {
this as Int
<!NI;DEBUG_INFO_SMARTCAST!>this<!> // error in NI: required Int, found Any?; just inferred to Any? in OI
}
y checkType { <!NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Any?>() }
y checkType { <!OI;TYPE_MISMATCH!>_<!><Int>() }
}
fun case_1(z: Any?) {
val y = z.run {
when (this) {
is String -> return@run <!NI;DEBUG_INFO_SMARTCAST!>this<!> // type mismatch in the new inference (required String, found Any?)
is Float -> ""
else -> return@run ""
}
}
y checkType { <!NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Any?>() }
y checkType { <!OI;TYPE_MISMATCH!>_<!><kotlin.String>() }
// y is inferred to Any?
}
fun case_2(z: Any?) {
val y = z.run {
when (this) {
is String -> <!DEBUG_INFO_SMARTCAST!>this<!>
is Float -> ""
else -> return@run ""
}
}
y checkType { _<kotlin.String>() }
// y is inferred to String
}
fun case_3(z: Any?) {
val y = z.let {
when (it) {
is String -> return@let <!NI;DEBUG_INFO_SMARTCAST!>it<!>
is Float -> ""
else -> return@let ""
}
}
y checkType { <!NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Any?>() }
y checkType { <!OI;TYPE_MISMATCH!>_<!><kotlin.String>() }
// y is inferred to String
}