diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaNullabilityChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaNullabilityChecker.kt index a175101638b..5cb3a4c2493 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaNullabilityChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaNullabilityChecker.kt @@ -156,7 +156,13 @@ class JavaNullabilityChecker : AdditionalTypeChecker { private fun isNullableTypeAgainstNotNullTypeParameter( subType: KotlinType, superType: KotlinType - ) = superType is NotNullTypeVariable && subType.isNullable() + ): Boolean { + if (superType !is NotNullTypeVariable) return false + return !AbstractNullabilityChecker.isSubtypeOfAny( + ClassicTypeCheckerContext(errorTypeEqualsToAnything = true) as AbstractTypeCheckerContext, + subType + ) + } override fun checkReceiver( receiverParameter: ReceiverParameterDescriptor, diff --git a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.fir.kt b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.fir.kt index 2279c091050..00e1edee4f5 100644 --- a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.fir.kt @@ -10,6 +10,8 @@ public interface SLRUMap { void takeVList(@NotNull List<@NotNull V> value); void takeEList(@NotNull List<@NotNull E> value); + + public K id(K value) { return null; } } // FILE: main.kt @@ -20,9 +22,20 @@ fun SLRUMap.getOrPut(value: V, l: List) { takeE(value) takeEList(l) + takeE(id(value)) if (value != null) { takeV(value) takeE(value) + takeE(id(value)) } } + +fun SLRUMap.getOrPutNN(value: V, l: List) { + takeV(value) + takeVList(l) + + takeE(value) + takeEList(l) + takeE(id(value)) +} diff --git a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.kt b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.kt index c09043b7615..bdb2edf8321 100644 --- a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.kt +++ b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.kt @@ -10,6 +10,8 @@ public interface SLRUMap { void takeVList(@NotNull List<@NotNull V> value); void takeEList(@NotNull List<@NotNull E> value); + + public K id(K value) { return null; } } // FILE: main.kt @@ -20,9 +22,20 @@ fun SLRUMap.getOrPut(value: V, l: List) { takeE(value) takeEList(l) + takeE(id(value)) if (value != null) { takeV(value) takeE(value) + takeE(id(value)) } } + +fun SLRUMap.getOrPutNN(value: V, l: List) { + takeV(value) + takeVList(l) + + takeE(value) + takeEList(l) + takeE(id(value)) +} diff --git a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.txt b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.txt index 2957bc8922a..79857304f0f 100644 --- a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.txt +++ b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.txt @@ -1,10 +1,12 @@ package public fun SLRUMap.getOrPut(/*0*/ value: V, /*1*/ l: kotlin.collections.List): kotlin.Unit +public fun SLRUMap.getOrPutNN(/*0*/ value: V, /*1*/ l: kotlin.collections.List): kotlin.Unit public interface SLRUMap { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public abstract fun id(/*0*/ value: K!): K! public abstract fun takeE(/*0*/ @org.jetbrains.annotations.NotNull value: E!!): kotlin.Unit public abstract fun takeEList(/*0*/ @org.jetbrains.annotations.NotNull value: kotlin.collections.(Mutable)List<@org.jetbrains.annotations.NotNull E!!>): kotlin.Unit public abstract fun takeV(/*0*/ @org.jetbrains.annotations.NotNull value: V!!): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.fir.kt b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.fir.kt index 70694844ab7..d1715154e98 100644 --- a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.fir.kt @@ -10,6 +10,8 @@ public interface SLRUMap { void takeVList(@NotNull List<@NotNull V> value); void takeEList(@NotNull List<@NotNull E> value); + + public K id(K value) { return null; } } // FILE: main.kt @@ -20,9 +22,20 @@ fun SLRUMap.getOrPut(value: V, l: List) { takeE(value) takeEList(l) + takeE(id(value)) if (value != null) { takeV(value) takeE(value) + takeE(id(value)) } } + +fun SLRUMap.getOrPutNN(value: V, l: List) { + takeV(value) + takeVList(l) + + takeE(value) + takeEList(l) + takeE(id(value)) +} diff --git a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.kt b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.kt index 9496564d17f..44884f759d2 100644 --- a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.kt +++ b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.kt @@ -10,6 +10,8 @@ public interface SLRUMap { void takeVList(@NotNull List<@NotNull V> value); void takeEList(@NotNull List<@NotNull E> value); + + public K id(K value) { return null; } } // FILE: main.kt @@ -20,9 +22,20 @@ fun SLRUMap.getOrPut(value: V, l: List) { takeE(value) takeEList(l) + takeE(id(value)) if (value != null) { takeV(value) takeE(value) + takeE(id(value)) } } + +fun SLRUMap.getOrPutNN(value: V, l: List) { + takeV(value) + takeVList(l) + + takeE(value) + takeEList(l) + takeE(id(value)) +} diff --git a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.txt b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.txt index 385cc65e60b..c0bf6d6aa9a 100644 --- a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.txt +++ b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.txt @@ -1,10 +1,12 @@ package public fun SLRUMap.getOrPut(/*0*/ value: V, /*1*/ l: kotlin.collections.List): kotlin.Unit +public fun SLRUMap.getOrPutNN(/*0*/ value: V, /*1*/ l: kotlin.collections.List): kotlin.Unit public interface SLRUMap { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public abstract fun id(/*0*/ value: K!): K! public abstract fun takeE(/*0*/ @org.jetbrains.annotations.NotNull value: E): kotlin.Unit public abstract fun takeEList(/*0*/ @org.jetbrains.annotations.NotNull value: kotlin.collections.(Mutable)List<@org.jetbrains.annotations.NotNull E>): kotlin.Unit public abstract fun takeV(/*0*/ @org.jetbrains.annotations.NotNull value: V): kotlin.Unit