EnhancedNullability annotation in IR

Fixes KT-40115 & KT-40117.

Move FlexibleNullability annotation to 'kotlin.internal.ir'.
This commit is contained in:
Dmitry Petrov
2020-08-31 11:04:10 +03:00
parent 0bff406a12
commit 8cb8284957
29 changed files with 514 additions and 178 deletions
@@ -0,0 +1,5 @@
// Test to ensure that we mark the backing field of a lateinit property
// as NotNull, even though the field is nullable in the JVM IR backend.
class A {
lateinit var x: A
}
@@ -0,0 +1,8 @@
@kotlin.Metadata
public final class A {
// source: 'lateInitNotNull.kt'
public field x: A
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getX(): A
public final method setX(@org.jetbrains.annotations.NotNull p0: A): void
}
@@ -0,0 +1,17 @@
// FILE: nullabilityAnnotationsForReturnType.kt
fun testNotNull(): String = ""
fun testNullable(): String? = ""
fun testJavaNotNull() = J.returnsNotNull()
fun testJavaNullable() = J.returnsNullable()
fun testJavaFlexible() = J.returnsFlexible()
// FILE: J.java
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class J {
public static @NotNull String returnsNotNull() { return ""; }
public static @Nullable String returnsNullable() { return ""; }
public static String returnsFlexible() { return ""; }
}
@@ -0,0 +1,9 @@
@kotlin.Metadata
public final class NullabilityAnnotationsForReturnTypeKt {
// source: 'nullabilityAnnotationsForReturnType.kt'
public final static method testJavaFlexible(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method testJavaNotNull(): java.lang.String
public final static @org.jetbrains.annotations.Nullable method testJavaNullable(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method testNotNull(): java.lang.String
public final static @org.jetbrains.annotations.Nullable method testNullable(): java.lang.String
}
@@ -0,0 +1,15 @@
// FILE: nullabilityAnnotationsOnDelegatedMembers.kt
class JImpl(j: J) : J by j
// FILE: J.java
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface J {
void takeNotNull(@NotNull String x);
void takeNullable(@Nullable String x);
void takeFlexible(String x);
@NotNull String returnNotNull();
@Nullable String returnNullable();
String returnsFlexible();
}
@@ -0,0 +1,12 @@
@kotlin.Metadata
public final class JImpl {
// source: 'nullabilityAnnotationsOnDelegatedMembers.kt'
private synthetic final field $$delegate_0: J
public method <init>(@org.jetbrains.annotations.NotNull p0: J): void
public @org.jetbrains.annotations.NotNull method returnNotNull(): java.lang.String
public @org.jetbrains.annotations.Nullable method returnNullable(): java.lang.String
public method returnsFlexible(): java.lang.String
public method takeFlexible(p0: java.lang.String): void
public method takeNotNull(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
public method takeNullable(@org.jetbrains.annotations.Nullable p0: java.lang.String): void
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
import java.util.Collections
class PlatformTypes {
fun simplyPlatform() = Collections.singletonList("")[0]
fun bothNullable() = Collections.emptyList<String>() ?: null
fun bothNotNull() = Collections.emptyList<String>()!!
}
@@ -0,0 +1,8 @@
@kotlin.Metadata
public final class PlatformTypes {
// source: 'platformTypes.kt'
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method bothNotNull(): java.util.List
public final @org.jetbrains.annotations.Nullable method bothNullable(): java.util.List
public final method simplyPlatform(): java.lang.String
}