"if-then to safe access" inspection: support call expression -> let

#KT-7675 Fixed
This commit is contained in:
Toshiaki Kameyama
2018-07-25 08:21:26 +03:00
committed by Mikhail Glukhikh
parent 2dcbf6aa34
commit f5cfec4a91
12 changed files with 172 additions and 3 deletions
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun convert(x: String, y: String) = ""
fun foo(a: String?, b: String) {
<caret>if (a != null) convert(a, b) else null
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun convert(x: String, y: String) = ""
fun foo(a: String?, b: String) {
a?.let { convert(it, b) }
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun convert(x: String, y: String) = ""
fun foo(a: Any?, b: String) {
<caret>if (a is String) convert(a, b) else null
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun convert(x: String, y: String) = ""
fun foo(a: Any?, b: String) {
(a as? String)?.let { convert(it, b) }
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun convert(x: String, y: Int) = ""
fun foo(a: String?, it: Int) {
<caret>if (a != null) convert(a, it) else null
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun convert(x: String, y: Int) = ""
fun foo(a: String?, it: Int) {
a?.let { it1 -> convert(it1, it) }
}
@@ -0,0 +1,12 @@
// WITH_RUNTIME
fun maybeFoo(): String? {
return "foo"
}
fun convert(x: String, y: Int) = ""
fun foo(it: Int) {
val foo = maybeFoo()
<caret>if (foo == null) else convert(foo, it)
}
@@ -0,0 +1,12 @@
// WITH_RUNTIME
fun maybeFoo(): String? {
return "foo"
}
fun convert(x: String, y: Int) = ""
fun foo(it: Int) {
maybeFoo()?.let { it1 -> convert(it1, it) }
}
@@ -167,4 +167,40 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Foldable if-then</description>
</problem>
<problem>
<file>call4.kt</file>
<line>10</line>
<module>light_idea_test_case</module>
<package>&lt;default&gt;</package>
<entry_point TYPE="file" FQNAME="temp:///src/call4.kt" />
<problem_class severity="INFO" attribute_key="INFO_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Foldable if-then</description>
</problem>
<problem>
<file>call3.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<package>&lt;default&gt;</package>
<entry_point TYPE="file" FQNAME="temp:///src/call3.kt" />
<problem_class severity="INFO" attribute_key="INFO_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Foldable if-then</description>
</problem>
<problem>
<file>call2.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<package>&lt;default&gt;</package>
<entry_point TYPE="file" FQNAME="temp:///src/call2.kt" />
<problem_class severity="INFO" attribute_key="INFO_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Foldable if-then</description>
</problem>
<problem>
<file>call.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<package>&lt;default&gt;</package>
<entry_point TYPE="file" FQNAME="temp:///src/call.kt" />
<problem_class severity="INFO" attribute_key="INFO_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Foldable if-then</description>
</problem>
</problems>