FIR checker: warn unnecessary non-null assertions
This commit is contained in:
committed by
Mikhail Glukhikh
parent
5229d4e4f4
commit
2ecb6733ed
@@ -27,13 +27,13 @@ fun bar(o: Any) {
|
||||
|
||||
}
|
||||
else {
|
||||
order!!.doSomething()
|
||||
order<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.doSomething()
|
||||
}
|
||||
if (order?.notExpired() ?: true) {
|
||||
|
||||
}
|
||||
else {
|
||||
order!!.doSomething()
|
||||
order<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.doSomething()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public data class Tag(public var tagName: String) {
|
||||
attributes.remove("id")
|
||||
}
|
||||
else {
|
||||
attributes["id"] = value!!
|
||||
attributes["id"] = value<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
attributes["id"] = value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ fun main() {
|
||||
val value: String? = ""
|
||||
if (value != null) {
|
||||
foo(Pair("val", value))
|
||||
foo(Pair("val", value!!))
|
||||
foo(Pair("val", value<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>))
|
||||
foo(Pair<String, String>("val", value))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@ operator fun <K, V> MutableMap<K, V>.set(k: K, v: V) {}
|
||||
|
||||
fun foo(a: MutableMap<String, String>, x: String?) {
|
||||
a[x!!] = x
|
||||
a[x] = x!!
|
||||
a[x] = x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
}
|
||||
|
||||
fun foo1(a: MutableMap<String, String>, x: String?) {
|
||||
<!INAPPLICABLE_CANDIDATE!>a[x]<!> = x!!
|
||||
a[x!!] = x
|
||||
a[x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = x
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
fun calc(x: List<String>?): Int {
|
||||
// After KT-5840 fix !! assertion should become unnecessary here
|
||||
x?.get(x!!.size - 1)
|
||||
// x?. or x!! above should not provide smart cast here
|
||||
return x<!UNSAFE_CALL!>.<!>size
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
fun calc(x: List<String>?): Int {
|
||||
// After KT-5840 fix !! assertion should become unnecessary here
|
||||
x?.get(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.size - 1)
|
||||
|
||||
+2
-2
@@ -10,5 +10,5 @@ fun foo(y: MyClass?): Int {
|
||||
fun bar(y: MyClass?) {
|
||||
y?.x!!.length
|
||||
// !! is NOT necessary here, because y?.x != null
|
||||
y!!.x
|
||||
}
|
||||
y<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.x
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user