Files
kotlin-fork/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2146.kt
T
Denis.Zharkov 2ecba6ac39 Remove WITH_NEW_INFERENCE directive from all tests
This directive anyway does not make test run twice with OI, and with NI
It only once run the test with specific settings (// LANGUAGE)
and ignores irrelevant (OI or NI tags)
2021-05-25 13:28:26 +03:00

55 lines
1.1 KiB
Kotlin
Vendored

//KT-2146 Nullability casts in when.
package kt2146
fun f1(s: Int?): Int {
return when (s) {
null -> 3
else -> <!DEBUG_INFO_SMARTCAST!>s<!>
}
}
fun f2(s: Int?): Int {
return when (s) {
!is Int -> <!TYPE_MISMATCH!>s<!>
else -> <!DEBUG_INFO_SMARTCAST!>s<!>
}
}
fun f3(s: Int?): Int {
return when (s) {
is Int -> <!DEBUG_INFO_SMARTCAST!>s<!>
else -> <!TYPE_MISMATCH!>s<!>
}
}
fun f4(s: Int?): Int {
return when {
s == 4 -> <!DEBUG_INFO_SMARTCAST!>s<!>
s == null -> <!DEBUG_INFO_CONSTANT, TYPE_MISMATCH!>s<!>
else -> <!DEBUG_INFO_SMARTCAST!>s<!>
}
}
fun f5(s: Int?): Int {
return when (s) {
s -> <!TYPE_MISMATCH!>s<!>
s!! -> <!DEBUG_INFO_SMARTCAST!>s<!>
s -> <!DEBUG_INFO_SMARTCAST!>s<!>
else -> 0
}
}
fun f6(s: Int?): Int {
return when {
s is Int -> <!DEBUG_INFO_SMARTCAST!>s<!>
else -> <!TYPE_MISMATCH!>s<!>
}
}
fun f7(s: Int?): Int {
return when {
s !is Int -> <!TYPE_MISMATCH!>s<!>
else -> <!DEBUG_INFO_SMARTCAST!>s<!>
}
}