Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/kt30927.fir.kt
T
Dmitriy Novozhilov e6b5cb5216 [TD] Update diagnostics test data due to new test runners
Update includes:
- Changing syntax of `OI/`NI` tags from `<!NI;TAG!>` to `<!TAG{NI}!>`
- Fix some incorrect directives
- Change order of diagnostics in some places
- Remove ignored diagnostics from FIR test data (previously `DIAGNOSTICS` didn't work)
- Update FIR dumps in some places and add `FIR_IDENTICAL` if needed
- Replace all JAVAC_SKIP with SKIP_JAVAC directive
2020-12-16 19:52:25 +03:00

52 lines
1.2 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
this // error in NI: required Int, found Any?; just inferred to Any? in OI
}
y checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Any?>() }
y checkType { _<Int>() }
}
fun case_1(z: Any?) {
val y = z.run {
when (this) {
is String -> return@run this // type mismatch in the new inference (required String, found Any?)
is Float -> ""
else -> return@run ""
}
}
y checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Any?>() }
y checkType { _<kotlin.String>() }
// y is inferred to Any?
}
fun case_2(z: Any?) {
val y = z.run {
when (this) {
is String -> 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 it
is Float -> ""
else -> return@let ""
}
}
y checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Any?>() }
y checkType { _<kotlin.String>() }
// y is inferred to String
}