FIR checker: differentiate UNSAFE_CALL from INAPPLICABLE_CANDIDATE
To do so, inside the root cause of inapplicable candidate errors, we will record expected/actual type of receiver, if any. That will help identifying inapplicable calls on nullable receiver.
This commit is contained in:
committed by
Mikhail Glukhikh
parent
4b823eca21
commit
e72ddbcbfe
Vendored
+4
-4
@@ -5,7 +5,7 @@ fun test_1(s: String?) {
|
||||
if (s?.check() == true) {
|
||||
s.length // Should be OK
|
||||
} else {
|
||||
s.<!INAPPLICABLE_CANDIDATE!>length<!> // Should be bad
|
||||
s.<!UNSAFE_CALL!>length<!> // Should be bad
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,13 @@ fun test_2(s: String?) {
|
||||
if (s?.check() == false) {
|
||||
s.length // Should be OK
|
||||
} else {
|
||||
s.<!INAPPLICABLE_CANDIDATE!>length<!> // Should be bad
|
||||
s.<!UNSAFE_CALL!>length<!> // Should be bad
|
||||
}
|
||||
}
|
||||
|
||||
fun test_3(s: String?) {
|
||||
if (s?.check() != true) {
|
||||
s.<!INAPPLICABLE_CANDIDATE!>length<!> // Should be bad
|
||||
s.<!UNSAFE_CALL!>length<!> // Should be bad
|
||||
} else {
|
||||
s.length // Should be OK
|
||||
}
|
||||
@@ -27,7 +27,7 @@ fun test_3(s: String?) {
|
||||
|
||||
fun test_4(s: String?) {
|
||||
if (s?.check() != false) {
|
||||
s.<!INAPPLICABLE_CANDIDATE!>length<!> // Should be bad
|
||||
s.<!UNSAFE_CALL!>length<!> // Should be bad
|
||||
} else {
|
||||
s.length // Should be OK
|
||||
}
|
||||
|
||||
+3
-3
@@ -5,7 +5,7 @@ fun String.let(block: () -> Unit) {}
|
||||
|
||||
fun test(x: String?) {
|
||||
x?.foo(x.length == 1)
|
||||
x.<!INAPPLICABLE_CANDIDATE!>length<!>
|
||||
x.<!UNSAFE_CALL!>length<!>
|
||||
}
|
||||
|
||||
interface A {
|
||||
@@ -27,12 +27,12 @@ fun test_3(x: Any) {
|
||||
|
||||
fun test_4(x: A?) {
|
||||
x?.id()?.bool()
|
||||
x.<!INAPPLICABLE_CANDIDATE{LT}!><!INAPPLICABLE_CANDIDATE{PSI}!>id<!>()<!>
|
||||
x.<!UNSAFE_CALL{LT}!><!UNSAFE_CALL{PSI}!>id<!>()<!>
|
||||
}
|
||||
|
||||
fun Any?.boo(b: Boolean) {}
|
||||
|
||||
fun test_5(x: A?) {
|
||||
x?.let { return }?.boo(x.bool())
|
||||
x.<!INAPPLICABLE_CANDIDATE{LT}!><!INAPPLICABLE_CANDIDATE{PSI}!>id<!>()<!>
|
||||
x.<!UNSAFE_CALL{LT}!><!UNSAFE_CALL{PSI}!>id<!>()<!>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user