Data flow values for Elvis / parenthesized expressions, smart casts on them

This commit is contained in:
Mikhail Glukhikh
2015-12-08 16:50:04 +03:00
parent 745a3aeeac
commit d024045638
10 changed files with 160 additions and 16 deletions
@@ -0,0 +1,37 @@
fun foo(s: Any?): String {
val t = when {
// To resolve: String U Nothing? = String?
s is String -> s
else -> null
} ?: ""
// Ideally we should have smart cast to String here
return <!TYPE_MISMATCH!>t<!>
}
fun bar(s: Any?): String {
// To resolve: String U Nothing? = String?
val t = (if (s == null) {
null
}
else {
val u: Any? = null
if (u !is String) return ""
u
}) ?: "xyz"
// Ideally we should have smart cast to String here
return <!TYPE_MISMATCH!>t<!>
}
fun baz(s: String?, r: String?): String {
val t = r ?: when {
s != null -> s
else -> ""
}
return <!DEBUG_INFO_SMARTCAST!>t<!>
}
fun withNull(s: String?): String {
val t = s ?: null
// Error: nullable
return <!TYPE_MISMATCH!>t<!>
}