IfThenToSafeAccessInspection: fix it works correctly for variable/operator call

#KT-30513 Fixed
#KT-17071 Fixed
This commit is contained in:
Toshiaki Kameyama
2020-01-06 17:49:29 +09:00
committed by Yan Zhulanow
parent 871ad2b909
commit 5095caee50
11 changed files with 107 additions and 2 deletions
@@ -0,0 +1,8 @@
// HIGHLIGHT: INFORMATION
fun test(foo: Foo?) {
<caret>if (foo != null) foo()
}
class Foo {
operator fun invoke() {}
}
@@ -0,0 +1,8 @@
// HIGHLIGHT: INFORMATION
fun test(foo: Foo?) {
foo?.invoke()
}
class Foo {
operator fun invoke() {}
}
@@ -0,0 +1,11 @@
class Foo(val bar: Bar)
class Bar {
operator fun invoke() {}
}
fun test(foo: Foo?) {
<caret>if (foo != null) {
foo.bar()
}
}
@@ -0,0 +1,9 @@
class Foo(val bar: Bar)
class Bar {
operator fun invoke() {}
}
fun test(foo: Foo?) {
foo?.bar?.invoke()
}
@@ -0,0 +1,4 @@
// HIGHLIGHT: INFORMATION
fun test(foo: (() -> Unit)?) {
<caret>if (foo != null) foo()
}
@@ -0,0 +1,4 @@
// HIGHLIGHT: INFORMATION
fun test(foo: (() -> Unit)?) {
foo?.invoke()
}
@@ -0,0 +1,7 @@
class Foo(val f: () -> Unit)
fun test(foo: Foo?) {
<caret>if (foo != null) {
foo.f()
}
}
@@ -0,0 +1,5 @@
class Foo(val f: () -> Unit)
fun test(foo: Foo?) {
foo?.f?.invoke()
}