[FIR] Harden check of argument type properly

Before this commit, nullable argument could match not null parameter.
Now we require also correct nullability that breaks some cases
This commit is contained in:
simon.ogorodnik
2020-01-28 14:17:24 +03:00
committed by Mikhail Glukhikh
parent fe779bf7bd
commit 34e6649d31
82 changed files with 171 additions and 173 deletions
@@ -15,7 +15,7 @@ class B {
fun test() {
if (A.x != null) {
useInt(A.x)
useInt(B.x)
<!INAPPLICABLE_CANDIDATE!>useInt<!>(B.x)
}
}
@@ -19,7 +19,7 @@ fun bar(x: String) = x
fun test(x: String?): Any {
val y = My.create()
val z = x ?: y!!
bar(y)
<!INAPPLICABLE_CANDIDATE!>bar<!>(y)
// !! / ?. is necessary here, because y!! above may not be executed
y?.hashCode()
y!!.hashCode()
@@ -6,10 +6,10 @@ class Test {
fun bar(a: Test, b: Test) {
if (a.foo != null) {
useInt(b.foo)
<!INAPPLICABLE_CANDIDATE!>useInt<!>(b.foo)
}
if (a.foo != null) {
useInt(foo)
<!INAPPLICABLE_CANDIDATE!>useInt<!>(foo)
}
if (this.foo != null) {
useInt(foo)
@@ -7,6 +7,6 @@ fun foo(a: MutableMap<String, String>, x: String?) {
}
fun foo1(a: MutableMap<String, String>, x: String?) {
a[x] = x!!
<!INAPPLICABLE_CANDIDATE!>a[x] = x!!<!>
a[x!!] = x
}
@@ -11,14 +11,14 @@ val i: Int? = 1
class A(val i: Int?) {
fun testUseFromClass() {
if (foo.i != null) {
useInt(i)
<!INAPPLICABLE_CANDIDATE!>useInt<!>(i)
}
}
}
fun testUseFromOtherPackage() {
if (bar.i != null) {
useInt(i)
<!INAPPLICABLE_CANDIDATE!>useInt<!>(i)
}
}
@@ -3,4 +3,4 @@ fun Any?.foo(my: My) = my === this
class My(val x: Any)
// my is nullable in brackets because Any?.foo has nullable receiver
fun foo(my: My?) = my?.x.foo(my)
fun foo(my: My?) = my?.x.<!INAPPLICABLE_CANDIDATE!>foo<!>(my)
@@ -7,5 +7,5 @@ fun bar(s: String): Int {
fun foo(m: MyClass): Int {
m.p = "xyz"
return bar(m.p)
return <!INAPPLICABLE_CANDIDATE!>bar<!>(m.p)
}