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
@@ -5,35 +5,35 @@ fun main() {
val a : Int? = null
val b : Int? = null
checkSubtype<Int>(a!!)
a!! + 2
a!!.plus(2)
a!!.plus(b!!)
2.plus(b!!)
2 + b!!
a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!> + 2
a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.plus(2)
a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.plus(b!!)
2.plus(b<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
2 + b<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
val c = 1
c!!
c<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
val d : Any? = null
if (d != null) {
d!!
d<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
// smart cast isn't needed, but is reported due to KT-4294
if (d is String) {
d!!
d<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
if (d is String?) {
if (d != null) {
d!!
d<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
if (d is String) {
d!!
d<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
}
}
val f : String = a!!
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><String>(a!!)
val f : String = a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><String>(a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
}