FIR checker: warn unnecessary non-null assertions
This commit is contained in:
committed by
Mikhail Glukhikh
parent
5229d4e4f4
commit
2ecb6733ed
+12
-12
@@ -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!>!!<!>)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user