Files
kotlin-fork/compiler/testData/foreignAnnotations/tests/androidRecently.kt
T
Denis Zharkov 9de174959e Support androidx under-migration-like nullability annotations
They are hardcoded to avoid having dependency from android.jar on
our annotations' jar with UnderMigration.

Even while it could be a compile-only dependency we need to make sure
that annotated types are read properly without RecentlyNonNull/RecentlyNullable
in the classpath

 #KT-24278 Fixed
2018-05-14 17:16:15 +03:00

55 lines
1.6 KiB
Kotlin
Vendored

// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// FILE: A.java
import androidx.annotation.*;
public class A<T> {
@RecentlyNullable public String field = null;
@RecentlyNullable
public String foo(@RecentlyNonNull String x, @RecentlyNullable CharSequence y) {
return "";
}
@RecentlyNonNull
public String bar() {
return "";
}
@RecentlyNullable
public T baz(@RecentlyNonNull T x) { return x; }
@RecentlyNonNull
public T baz2(@RecentlyNullable T x) { return x; }
}
// FILE: main.kt
fun main(a: A<String>, a1: A<String?>) {
a.foo("", null)?.length
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo("", null)<!>.length
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
a.bar().length
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
a.field?.length
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz("")<!>.length
a.baz("")?.length
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)<!>.length
a1.baz("")!!.length
a1.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)!!.length
a.baz2("").length
a.baz2("")<!UNNECESSARY_SAFE_CALL!>?.<!>length
a.baz2("")<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
a.baz2(null).length
a.baz2(null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
a.baz2(null)<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
}