Reporting unnecessary safe calls on Java's @NotNull values
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// FILE: p/J.java
|
||||
package p;
|
||||
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
public class J {
|
||||
@NotNull
|
||||
public static J staticNN;
|
||||
@Nullable
|
||||
public static J staticN;
|
||||
public static J staticJ;
|
||||
|
||||
public void foo() {}
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
|
||||
import p.*
|
||||
|
||||
fun test() {
|
||||
// @NotNull platform type
|
||||
val platformNN = J.staticNN
|
||||
// @Nullable platform type
|
||||
val platformN = J.staticN
|
||||
// platform type with no annotation
|
||||
val platformJ = J.staticJ
|
||||
|
||||
platformNN<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
|
||||
platformN?.foo()
|
||||
platformJ?.foo()
|
||||
|
||||
if (platformNN != null) {
|
||||
platformNN<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
|
||||
}
|
||||
|
||||
if (platformN != null) {
|
||||
platformN<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
|
||||
}
|
||||
|
||||
if (platformJ != null) {
|
||||
platformJ<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
internal fun test(): kotlin.Unit
|
||||
Reference in New Issue
Block a user