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
@@ -388,49 +388,49 @@ fun poll66(): Flow<String> {
fun poll7(): Flow<String> {
return flow {
val inv = ::bar!!
val inv = ::bar<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv(<!NO_VALUE_FOR_PARAMETER!>)<!>
}
}
fun poll71(): Flow<String> {
return flow {
val inv = ::bar2!!
val inv = ::bar2<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv()
}
}
fun poll72(): Flow<String> {
return flow {
val inv = ::bar3!!
val inv = ::bar3<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv()
}
}
fun poll73(): Flow<String> {
return flow {
val inv = ::bar4!!
val inv = ::bar4<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv
}
}
fun poll74(): Flow<String> {
return flow {
val inv = ::bar5!!
val inv = ::bar5<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv
}
}
fun poll75(): Flow<String> {
return flow {
val inv = ::Foo6!!
val inv = ::Foo6<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv
}
}
fun poll76(): Flow<String> {
return flow {
val inv = ::Foo7!!
val inv = ::Foo7<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv
}
}
@@ -36,21 +36,21 @@ class Flow<out R>(private val block: suspend FlowCollector<R>.() -> Unit)
fun poll71(): Flow<String> {
return flow {
val inv = ::bar2!!
val inv = ::bar2<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv()
}
}
fun poll73(): Flow<String> {
return flow {
val inv = ::bar4!!
val inv = ::bar4<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv
}
}
fun poll75(): Flow<String> {
return flow {
val inv = ::Foo6!!
val inv = ::Foo6<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv
}
}
@@ -37,49 +37,49 @@ class Flow<out R>(private val block: suspend FlowCollector<R>.() -> Unit)
fun poll7(): Flow<String> {
return flow {
val inv = ::bar!!
val inv = ::bar<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv(<!NO_VALUE_FOR_PARAMETER!>)<!>
}
}
fun poll71(): Flow<String> {
return flow {
val inv = ::bar2!!
val inv = ::bar2<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv()
}
}
fun poll72(): Flow<String> {
return flow {
val inv = ::bar3!!
val inv = ::bar3<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv()
}
}
fun poll73(): Flow<String> {
return flow {
val inv = ::bar4!!
val inv = ::bar4<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv
}
}
fun poll74(): Flow<String> {
return flow {
val inv = ::bar5!!
val inv = ::bar5<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv
}
}
fun poll75(): Flow<String> {
return flow {
val inv = ::Foo6!!
val inv = ::Foo6<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv
}
}
fun poll76(): Flow<String> {
return flow {
val inv = ::Foo7!!
val inv = ::Foo7<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv
}
}
@@ -119,28 +119,28 @@ fun poll5(): Flow<String> {
fun poll7(): Flow<String> {
return flow {
val inv = {}!!
val inv = {}<!NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION!>!!<!>
inv()
}
}
fun poll71(): Flow<String> {
return flow {
val inv = {1f}!!
val inv = {1f}<!NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION!>!!<!>
inv()
}
}
fun poll72(): Flow<String> {
return flow {
val inv = {{}}!!
val inv = {{}}<!NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION!>!!<!>
inv()
}
}
fun poll73(): Flow<String> {
return flow {
val inv = ({})!!
val inv = ({})<!NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION!>!!<!>
inv
}
}
@@ -189,7 +189,7 @@ fun poll85(): Flow<String> {
fun poll86(): Flow<String> {
return flow {
val inv = {({"1"})}!! in setOf({({"1f"})}!!)
val inv = {({"1"})}<!NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION!>!!<!> in setOf({({"1f"})}<!NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION!>!!<!>)
<!UNRESOLVED_REFERENCE!>inv<!>()
}
}
@@ -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()!!)
}
}
@@ -5,7 +5,7 @@ import java.lang.Exception
fun <K> id(arg: K): K = arg
fun test() {
id(<!UNRESOLVED_REFERENCE!>unresolved<!>)!!
id(<!UNRESOLVED_REFERENCE!>unresolved<!>)<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
<!UNRESOLVED_REFERENCE!>unresolved<!>!!!!
try {
id(<!UNRESOLVED_REFERENCE!>unresolved<!>)
@@ -234,37 +234,37 @@ fun poll66() {
}
fun poll7() {
val inv = ::bar!!
val inv = ::bar<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv(<!NO_VALUE_FOR_PARAMETER!>)<!>
}
fun poll71() {
val inv = ::bar2!!
val inv = ::bar2<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv()
}
fun poll72() {
val inv = ::bar3!!
val inv = ::bar3<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv(<!NO_VALUE_FOR_PARAMETER!>)<!>
}
fun poll73() {
val inv = ::bar4!!
val inv = ::bar4<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv
}
fun poll74() {
val inv = ::bar5!!
val inv = ::bar5<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv
}
fun poll75() {
val inv = ::Foo6!!
val inv = ::Foo6<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv
}
fun poll76() {
val inv = ::Foo7!!
val inv = ::Foo7<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
inv
}