diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated.java index 3ab4739fe63..6c6ffac2af6 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated.java @@ -925,6 +925,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated extends A runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48261.kt"); } + @Test + @TestMetadata("kt48778.kt") + public void testKt48778() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48778.kt"); + } + @Test @TestMetadata("methodWithTypeParameter.kt") public void testMethodWithTypeParameter() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java index 3c4ab38c7e0..f4bde3a6554 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java @@ -925,6 +925,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTest runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48261.kt"); } + @Test + @TestMetadata("kt48778.kt") + public void testKt48778() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48778.kt"); + } + @Test @TestMetadata("methodWithTypeParameter.kt") public void testMethodWithTypeParameter() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsSourceJavaTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsSourceJavaTestGenerated.java index 82530bc5020..a008a340a76 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsSourceJavaTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsSourceJavaTestGenerated.java @@ -925,6 +925,12 @@ public class FirOldFrontendForeignAnnotationsSourceJavaTestGenerated extends Abs runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48261.kt"); } + @Test + @TestMetadata("kt48778.kt") + public void testKt48778() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48778.kt"); + } + @Test @TestMetadata("methodWithTypeParameter.kt") public void testMethodWithTypeParameter() throws Exception { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt index 3bab1500451..fb65eaaacc0 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.annotations.CompositeAnnotations import org.jetbrains.kotlin.resolve.calls.inference.isCaptured import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableFromCallableDescriptor +import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor import org.jetbrains.kotlin.resolve.calls.inference.substitute import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.NewCapturedType @@ -157,7 +158,11 @@ interface NewTypeSubstitutor : TypeSubstitutorMarker { replacement = replacement.makeDefinitelyNotNullOrNotNull() } if (type is CustomTypeParameter) { - replacement = type.substitutionResult(replacement).unwrap() + replacement = type.substitutionResult(replacement).unwrap().run { + if (type is NotNullTypeVariable && replacement.constructor is TypeVariableTypeConstructor) { + makeDefinitelyNotNullOrNotNull() + } else this + } } return replacement diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt index c2aa20fbe18..c56d8c881c4 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/TypeParameterBounds.kt @@ -23,24 +23,24 @@ public class Test {} // jspecify_nullness_mismatch, jspecify_nullness_mismatch fun main(a1: A<Any?>, a2: A, b1: B<Any?>, b2: B, x: T): Unit { a1.foo(null) - // jspecify_nullness_mismatch - a1.bar<T?>(null) + // jspecify_nullness_mismatch, jspecify_nullness_mismatch + a1.bar<T?>(null) a1.bar(x) a2.foo(null) - // jspecify_nullness_mismatch - a2.bar<T?>(null) + // jspecify_nullness_mismatch, jspecify_nullness_mismatch + a2.bar<T?>(null) a2.bar(x) // jspecify_nullness_mismatch b1.foo(null) - // jspecify_nullness_mismatch - b1.bar<T?>(null) + // jspecify_nullness_mismatch, jspecify_nullness_mismatch + b1.bar<T?>(null) b1.bar(x) // jspecify_nullness_mismatch b2.foo(null) - // jspecify_nullness_mismatch - b2.bar<T?>(null) + // jspecify_nullness_mismatch, jspecify_nullness_mismatch + b2.bar<T?>(null) b2.bar(x) } diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48778.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48778.kt new file mode 100644 index 00000000000..641110863d0 --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48778.kt @@ -0,0 +1,14 @@ +// FIR_IDENTICAL +// WITH_RUNTIME + +// FILE: Java.java +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; + +public interface Java { + @NonNull T getFoo(); +} + +// FILE: main.kt +fun usingMethod(java : Java) : String = java.getFoo() +fun usingProperty(java : Java) : String = java.foo diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48778.txt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48778.txt new file mode 100644 index 00000000000..2eb59226ee2 --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48778.txt @@ -0,0 +1,11 @@ +package + +public fun usingMethod(/*0*/ java: Java): kotlin.String +public fun usingProperty(/*0*/ java: Java): kotlin.String + +public interface Java { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + @org.checkerframework.checker.nullness.qual.NonNull public abstract fun getFoo(): @org.checkerframework.checker.nullness.qual.NonNull T + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.kt b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.kt index f0f37293165..c8a764df606 100644 --- a/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.kt +++ b/compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableWarnings.kt @@ -21,13 +21,13 @@ fun SLRUMap.getOrPut(value: V, l: List) { takeV(value) takeVList(l) - takeE(value) - takeEList(l) - takeE(id(value)) + takeE(value) + takeEList(l) + takeE(id(value)) if (value != null) { takeV(value) - takeE(value) + takeE(value) takeE(id(value)) } } diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalOf.txt b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalOf.txt index 7638f81b666..26d2e30bafc 100644 --- a/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalOf.txt +++ b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalOf.txt @@ -3,7 +3,7 @@ import java.util.* fun use() { val x: String? = "x" Optional.of(x) - // UNSAFE_CALL_ERROR + // SUCCESS // ORIGINAL: fun of(T): Optional defined in java.util.Optional // SUBSTITUTED: fun of(String): Optional defined in java.util.Optional diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaTestGenerated.java index d46e1232411..cc4040602e9 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaTestGenerated.java @@ -925,6 +925,12 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48261.kt"); } + @Test + @TestMetadata("kt48778.kt") + public void testKt48778() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48778.kt"); + } + @Test @TestMetadata("methodWithTypeParameter.kt") public void testMethodWithTypeParameter() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java index 0d8c86fb688..6651aebfe73 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java @@ -925,6 +925,12 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48261.kt"); } + @Test + @TestMetadata("kt48778.kt") + public void testKt48778() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48778.kt"); + } + @Test @TestMetadata("methodWithTypeParameter.kt") public void testMethodWithTypeParameter() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsSourceJavaTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsSourceJavaTestGenerated.java index ac848241006..93ec1ec5715 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsSourceJavaTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsSourceJavaTestGenerated.java @@ -925,6 +925,12 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48261.kt"); } + @Test + @TestMetadata("kt48778.kt") + public void testKt48778() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/misc/kt48778.kt"); + } + @Test @TestMetadata("methodWithTypeParameter.kt") public void testMethodWithTypeParameter() throws Exception {