Take into account data flow info changes for special call (if/when/elvis/!!) arguments #KT-10824 Fixed

Smart casts on complex expressions look as no more possible
This commit is contained in:
Mikhail Glukhikh
2016-01-28 14:19:45 +03:00
parent 7c59592212
commit ed8ccdc15a
15 changed files with 117 additions and 25 deletions
@@ -15,10 +15,10 @@ fun bar(s: Any?): String {
else {
val u: Any? = null
if (u !is String) return ""
u
<!DEBUG_INFO_SMARTCAST!>u<!>
}) ?: "xyz"
// Ideally we should have smart cast to String here
return <!TYPE_MISMATCH!>t<!>
return t
}
fun baz(s: String?, r: String?): String {
@@ -5,10 +5,10 @@ fun baz(s: String?): String {
else if (s == "") {
val u: String? = null
if (u == null) return ""
u
<!DEBUG_INFO_SMARTCAST!>u<!>
}
else {
s
<!DEBUG_INFO_SMARTCAST!>s<!>
}
return <!DEBUG_INFO_SMARTCAST!>t<!>
return t
}
@@ -1,11 +1,11 @@
fun baz(s: String?, b: Boolean?): String {
val t = if (if (b == null) return "" else <!DEBUG_INFO_SMARTCAST!>b<!>) {
if (s == null) return ""
s
<!DEBUG_INFO_SMARTCAST!>s<!>
}
else {
if (s != null) return <!DEBUG_INFO_SMARTCAST!>s<!>
""
}
return <!DEBUG_INFO_SMARTCAST!>t<!>
return t
}
@@ -1,11 +1,11 @@
fun baz(s: String?, u: String?): String {
val t = when(if (u == null) return "" else <!DEBUG_INFO_SMARTCAST!>u<!>) {
"abc" -> u
"abc" -> <!DEBUG_INFO_SMARTCAST!>u<!>
"" -> {
if (s == null) return ""
s
<!DEBUG_INFO_SMARTCAST!>s<!>
}
else -> u
else -> <!DEBUG_INFO_SMARTCAST!>u<!>
}
return <!DEBUG_INFO_SMARTCAST!>t<!>
return t
}
@@ -7,9 +7,9 @@ fun baz(s: String?): String {
val u: String? = null
if (u == null) return ""
// !! is detected as unnecessary here
u
<!DEBUG_INFO_SMARTCAST!>u<!>
}
return <!DEBUG_INFO_SMARTCAST!>t<!>
return t
}
fun foo(s: String?): String {
@@ -1,9 +1,9 @@
fun baz(s: String?): String {
val t = if (s != null) s
val t = if (s != null) <!DEBUG_INFO_SMARTCAST!>s<!>
else {
val u: String? = null
if (u == null) return ""
u
<!DEBUG_INFO_SMARTCAST!>u<!>
}
return <!DEBUG_INFO_SMARTCAST!>t<!>
return t
}
@@ -1,10 +1,10 @@
fun baz(s: String?): Int {
return <!DEBUG_INFO_SMARTCAST!>if (s == null) {
return if (s == null) {
""
}
else {
val u: String? = null
if (u == null) return 0
u
}<!>.length
<!DEBUG_INFO_SMARTCAST!>u<!>
}.length
}
@@ -2,12 +2,12 @@ fun baz(s: String?, u: String?): String {
val t = when(s) {
is String -> {
if (u == null) return <!DEBUG_INFO_SMARTCAST!>s<!>
u
<!DEBUG_INFO_SMARTCAST!>u<!>
}
else -> {
if (u == null) return ""
u
<!DEBUG_INFO_SMARTCAST!>u<!>
}
}
return <!DEBUG_INFO_SMARTCAST!>t<!>
return t
}