Files
kotlin-fork/compiler/testData/diagnostics/tests/dataFlow/EmptyIf.kt
T
Alexander Udalov 4cd4026174 Support empty if-statements
Type-check "if (...) ;" to Unit, report "implicit cast to Unit", propagate data
flow info out of its condition

 #KT-2478 Fixed
2013-12-04 15:19:47 +04:00

23 lines
404 B
Kotlin

fun f1(s: String?) {
if (s!! == "");
s : String
}
fun f2(s: Number?) {
if (s is Int);
<!TYPE_MISMATCH!>s<!> : Int
if (s as Int == 42);
s : Int
}
fun f3(s: Number?) {
if (s is Int && s as Int == 42);
<!TYPE_MISMATCH!>s<!> : Int
}
fun f4(s: Int?) {
var u = <!IMPLICIT_CAST_TO_UNIT_OR_ANY!>if (s!! == 42)<!>;
if (u == Unit.VALUE) u = if (s == 239);
return u
}