Fixed some cases when smart cast problems were not detected

This commit is contained in:
Valentin Kipyatkov
2016-04-22 21:39:11 +03:00
parent fe52bed74e
commit 833f62e9b9
10 changed files with 127 additions and 30 deletions
@@ -0,0 +1,11 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.map{}.firstOrNull{}'"
fun foo(list: List<String>, o: Any): Int? {
if (o is CharSequence) {
<caret>return list
.map { it.length + (o as String).capitalize().hashCode() }
.map { it * o.length }
.firstOrNull { it > 1000 }
}
return 0
}
@@ -0,0 +1,13 @@
// WITH_RUNTIME
// INTENTION_TEXT: "Replace with 'map{}.map{}.firstOrNull{}'"
fun foo(list: List<String>, o: Any): Int? {
if (o is CharSequence) {
<caret>for (s in list) {
val a = s.length + (o as String).capitalize().hashCode()
val x = a * o.length
if (x > 1000) return x
}
return null
}
return 0
}
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
fun foo(list: List<Any>): String? {
<caret>for (o in list) {
if (bar(o as String)) {
return o
}
}
return null
}
fun bar(s: String): Boolean = true
@@ -0,0 +1,14 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
fun foo(list: List<Any>): String? {
var v: String? = null
<caret>for (o in list) {
if (bar(o as String)) {
v = o
break
}
}
return v
}
fun bar(s: String): Boolean = true
@@ -0,0 +1,11 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
fun foo(list: List<Any>, target: MutableCollection<String>) {
<caret>for (o in list) {
if (bar(o as String)) {
target.add(o)
}
}
}
fun bar(s: String): Boolean = true