FIR checker: warn unnecessary non-null assertions

This commit is contained in:
Jinseong Jeon
2021-04-01 11:44:47 -07:00
committed by Mikhail Glukhikh
parent 5229d4e4f4
commit 2ecb6733ed
72 changed files with 268 additions and 246 deletions
@@ -11,23 +11,23 @@ interface B {
fun test(u: A?, x: A?, y: A?, z: A?, w: A, v: A?) {
u?.b?.foo()!! // was UNNECESSARY_SAFE_CALL everywhere, because result type (of 'foo()') wasn't made nullable
u!!.b?.foo()!!
x?.b!!.foo()!!
u!!.b?.foo()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
x?.b!!.foo()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
// x?.b is not null
x!!.b!!.foo()!!
x!!.b<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.foo()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
y?.nb?.foo()!!
y!!.nb?.foo()!!
z?.nb!!.foo()!!
z?.nb!!.foo()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
// z?.nb is not null
z!!.nb!!.foo()!!
z!!.nb!!.foo()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
w.b?.foo()!!
w.b!!.foo()!!
w.b?.foo()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
w.b<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.foo()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
w.nb?.foo()!!
w.nb!!.foo()!!
w.nb!!.foo()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
v!!.b.foo()!!
v!!.b.foo()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
fun B?.bar(): Int = 1
@@ -36,6 +36,6 @@ fun B?.baz(): Int? = 1
fun doInt(i: Int) = i
fun test(a: A?) {
doInt(a?.b.bar()!!)
doInt(a?.b.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
doInt(a?.b.baz()!!)
}
}