FIR checker: warn unnecessary non-null assertions
This commit is contained in:
committed by
Mikhail Glukhikh
parent
5229d4e4f4
commit
2ecb6733ed
+5
-5
@@ -20,26 +20,26 @@ import libModule.*
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
fun case1() {
|
||||
val res = JavaClass.FALSE!!
|
||||
val res = JavaClass.FALSE<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
fun case2() {
|
||||
val x = JavaClass.obj!!
|
||||
val x = JavaClass.obj<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
fun case3() {
|
||||
val a = false
|
||||
val x = a!!
|
||||
val x = a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 4
|
||||
fun case4() {
|
||||
val x = "weds"!!
|
||||
val x = "weds"<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 5
|
||||
fun case5(nothing: Nothing) {
|
||||
val y = nothing!!
|
||||
val y = nothing<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -55,7 +55,7 @@ fun case_1(value_1: Int?) {
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
fun case_2(value_1: Int?) {
|
||||
if (!contracts.case_2(value_1)!!) {
|
||||
if (!contracts.case_2(value_1)<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>) {
|
||||
value_1<!UNSAFE_CALL!>.<!>inv()
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -159,6 +159,6 @@ class case_10_class {
|
||||
*/
|
||||
fun case_11(value_1: Any?, value_2: Any?, value_3: Any?) {
|
||||
funWithReturnsAndInvertCondition(value_1 !is String || value_2 !is Number || value_3 !is Any?)
|
||||
println(value_1!!.length)
|
||||
println(value_1<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length)
|
||||
println(value_2?.toByte())
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ fun case_25(x: Boolean?) {
|
||||
*/
|
||||
fun case_26(x: Boolean?) {
|
||||
while (true) {
|
||||
for (i in listOf(break, x!!, x!!)) {
|
||||
for (i in listOf(break, x!!, x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ fun case_25(x: Boolean?) {
|
||||
*/
|
||||
fun case_26(x: Boolean?) {
|
||||
while (true) {
|
||||
for (i in listOf(break, x as Boolean, x!!)) {
|
||||
for (i in listOf(break, x as Boolean, x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ fun case_6(x: Class?) {
|
||||
* ISSUES: KT-30376
|
||||
*/
|
||||
fun case_7(x: Class) {
|
||||
if (x!!.prop_8?.prop_8?.prop_8?.prop_8 != null) {
|
||||
if (x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.prop_8?.prop_8?.prop_8?.prop_8 != null) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Class")!>x<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Class")!>x<!>.prop_8
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Class")!>x<!>.prop_8<!UNSAFE_CALL!>.<!>prop_8
|
||||
@@ -113,7 +113,7 @@ fun case_7(x: Class) {
|
||||
* ISSUES: KT-30376
|
||||
*/
|
||||
fun case_8(x: Class) {
|
||||
if (x!!.prop_8?.prop_8?.prop_8?.prop_8 != null) {
|
||||
if (x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.prop_8?.prop_8?.prop_8?.prop_8 != null) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Class")!>x<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Class")!>x<!>.prop_8
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Class")!>x<!>.prop_8<!UNSAFE_CALL!>.<!>prop_8
|
||||
|
||||
@@ -137,7 +137,7 @@ fun case_10(x: Any?, z: Any, b: Boolean?) {
|
||||
// TESTCASE NUMBER: 11
|
||||
fun case_11(x: Any?, z: Any, b: Boolean?) {
|
||||
while (true) {
|
||||
var y = x ?: if (b == true) continue!! else if (!(b != false)) return else break ?: break::class
|
||||
var y = x ?: if (b == true) continue<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!> else if (!(b != false)) return else break ?: break::class
|
||||
z !== y && if (b == true) return else if (b === false) null!!else throw Exception()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>y<!>
|
||||
@@ -148,7 +148,7 @@ fun case_11(x: Any?, z: Any, b: Boolean?) {
|
||||
// TESTCASE NUMBER: 12
|
||||
fun case_12(x: Any?, z: Any, b: Boolean?) {
|
||||
while (true) {
|
||||
var y = select(x) ?: if (b == true) continue!! else if (!(b != false)) return else break ?: break::class
|
||||
var y = select(x) ?: if (b == true) continue<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!> else if (!(b != false)) return else break ?: break::class
|
||||
select(z) !== y && if (b == true) return else if (b === false) null!!else throw Exception()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>x<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>y<!>
|
||||
|
||||
@@ -31,7 +31,7 @@ fun case_3(x: ClassWithThreeTypeParameters<*, *, *>) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("ClassWithThreeTypeParameters<*, *, *> & InterfaceWithTwoTypeParameters<*, *> & ClassWithThreeTypeParameters<*, *, *>")!>x<!>.x
|
||||
x.y
|
||||
x.z
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters<*, *> & ClassWithThreeTypeParameters<*, *, *>")!>x!!<!>.ip2test()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters<*, *> & ClassWithThreeTypeParameters<*, *, *>")!>x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!><!>.ip2test()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("ClassWithThreeTypeParameters<*, *, *> & InterfaceWithTwoTypeParameters<*, *> & ClassWithThreeTypeParameters<*, *, *>")!>x<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("ClassWithThreeTypeParameters<*, *, *> & InterfaceWithTwoTypeParameters<*, *> & ClassWithThreeTypeParameters<*, *, *>")!>x<!>.x
|
||||
}
|
||||
@@ -45,7 +45,7 @@ fun case_4(x: ClassWithSixTypeParameters<*, *, *, *, *, *>?) {
|
||||
x.y
|
||||
x.z
|
||||
x.u
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters<*, *> & ClassWithSixTypeParameters<*, *, *, *, *, *>")!>x!!<!>.ip2test()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters<*, *> & ClassWithSixTypeParameters<*, *, *, *, *, *>")!>x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!><!>.ip2test()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("ClassWithSixTypeParameters<*, *, *, *, *, *>? & InterfaceWithTwoTypeParameters<*, *> & ClassWithSixTypeParameters<*, *, *, *, *, *>")!>x<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("ClassWithSixTypeParameters<*, *, *, *, *, *>? & InterfaceWithTwoTypeParameters<*, *> & ClassWithSixTypeParameters<*, *, *, *, *, *>")!>x<!>.x
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ fun case_6(x: Any?) {
|
||||
|
||||
// TESTCASE NUMBER: 7
|
||||
fun case_7(x: Boolean?) {
|
||||
if (x != null && x!!) {
|
||||
if (x != null && x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Boolean? & kotlin.Boolean")!>x<!>.not()
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Boolean")!>select(x)<!>.not()
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ fun case_22(z: Any?) {
|
||||
fun case_23(z: Any?) {
|
||||
val y = z.run {
|
||||
when (this) {
|
||||
true -> this!!
|
||||
true -> this<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
0.0 -> this as Any
|
||||
else -> this!!
|
||||
}
|
||||
@@ -276,7 +276,7 @@ fun case_23(z: Any?) {
|
||||
fun case_24(z: Any?) {
|
||||
val y = z.let {
|
||||
when (it) {
|
||||
true -> it!!
|
||||
true -> it<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
0.0 -> it as Any
|
||||
else -> it!!
|
||||
}
|
||||
@@ -292,7 +292,7 @@ fun case_25(z: Any?) {
|
||||
true -> this
|
||||
if (true) this as Int else this as Float -> this
|
||||
return@run this as Float -> this
|
||||
else -> this!!
|
||||
else -> this<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
}
|
||||
}
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>y<!>
|
||||
@@ -306,7 +306,7 @@ fun case_26(z: Any?) {
|
||||
true -> it
|
||||
if (true) it as Int else it as Float -> it
|
||||
return@let it as Int -> it
|
||||
else -> it!!
|
||||
else -> it<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
}
|
||||
}
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>y<!>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
fun case_1(x: Any) {
|
||||
if (x is String) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>x!!<!>.length
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!><!>.length
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.String")!>x<!>
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ fun case_2(x: Any?) {
|
||||
*/
|
||||
fun case_3(x: Any) {
|
||||
if (x is Map.Entry<*, *>) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map.Entry<*, *>")!>x!!<!>.key
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map.Entry<*, *>")!>x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!><!>.key
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.collections.Map.Entry<*, *>")!>x<!>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ fun case_4(x: Any?) {
|
||||
|
||||
// TESTCASE NUMBER: 5
|
||||
fun case_5(x: Class) {
|
||||
if (x!!.prop_8 != null) {
|
||||
if (x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.prop_8 != null) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Class")!>x<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Class")!>x<!>.prop_8<!UNSAFE_CALL!>.<!>prop_8
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user