diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.fir.kt new file mode 100644 index 00000000000..f99226b806b --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.fir.kt @@ -0,0 +1,17 @@ +// JSPECIFY_STATE: strict +// !LANGUAGE: +TypeEnhancementImprovementsInStrictMode +// FILE: J1.java +import org.jetbrains.annotations.Nullable; + +public interface J1 { + @Nullable + public static T foo(J1 x) { return null; } +} + +// FILE: J2.java +import org.jspecify.nullness.Nullable; + +public interface J2 extends J1 { } + +// FILE: kotlin.kt +private fun J2<*>.bar() = J1.foo(this) diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.fir.txt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.fir.txt new file mode 100644 index 00000000000..a30bd47201f --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.fir.txt @@ -0,0 +1,18 @@ +package + +private fun J2<*>.bar(): @org.jspecify.nullness.Nullable kotlin.Any? + +public interface J1 { + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + @org.jetbrains.annotations.Nullable public open fun foo(/*0*/ x: J1!): @org.jetbrains.annotations.Nullable T? +} + +public interface J2 : J1 { + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.kt new file mode 100644 index 00000000000..f99226b806b --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.kt @@ -0,0 +1,17 @@ +// JSPECIFY_STATE: strict +// !LANGUAGE: +TypeEnhancementImprovementsInStrictMode +// FILE: J1.java +import org.jetbrains.annotations.Nullable; + +public interface J1 { + @Nullable + public static T foo(J1 x) { return null; } +} + +// FILE: J2.java +import org.jspecify.nullness.Nullable; + +public interface J2 extends J1 { } + +// FILE: kotlin.kt +private fun J2<*>.bar() = J1.foo(this) diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.txt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.txt new file mode 100644 index 00000000000..a30bd47201f --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.txt @@ -0,0 +1,18 @@ +package + +private fun J2<*>.bar(): @org.jspecify.nullness.Nullable kotlin.Any? + +public interface J1 { + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + @org.jetbrains.annotations.Nullable public open fun foo(/*0*/ x: J1!): @org.jetbrains.annotations.Nullable T? +} + +public interface J2 : J1 { + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.fir.kt new file mode 100644 index 00000000000..535765d5a8d --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.fir.kt @@ -0,0 +1,16 @@ +// JSPECIFY_STATE: warn +// FILE: J1.java +import org.jetbrains.annotations.Nullable; + +public interface J1 { + @Nullable + public static T foo(J1 x) { return null; } +} + +// FILE: J2.java +import org.jspecify.nullness.Nullable; + +public interface J2 extends J1 { } + +// FILE: kotlin.kt +private fun J2<*>.bar() = J1.foo(this) diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.fir.txt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.fir.txt new file mode 100644 index 00000000000..2b3976fc916 --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.fir.txt @@ -0,0 +1,18 @@ +package + +private fun J2<*>.bar(): @org.jspecify.nullness.Nullable kotlin.Any? + +public interface J1 { + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + @org.jetbrains.annotations.Nullable public open fun foo(/*0*/ x: J1!): @org.jetbrains.annotations.Nullable T? +} + +public interface J2 : J1 { + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.kt new file mode 100644 index 00000000000..535765d5a8d --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.kt @@ -0,0 +1,16 @@ +// JSPECIFY_STATE: warn +// FILE: J1.java +import org.jetbrains.annotations.Nullable; + +public interface J1 { + @Nullable + public static T foo(J1 x) { return null; } +} + +// FILE: J2.java +import org.jspecify.nullness.Nullable; + +public interface J2 extends J1 { } + +// FILE: kotlin.kt +private fun J2<*>.bar() = J1.foo(this) diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.txt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.txt new file mode 100644 index 00000000000..2b3976fc916 --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.txt @@ -0,0 +1,18 @@ +package + +private fun J2<*>.bar(): @org.jspecify.nullness.Nullable kotlin.Any? + +public interface J1 { + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + @org.jetbrains.annotations.Nullable public open fun foo(/*0*/ x: J1!): @org.jetbrains.annotations.Nullable T? +} + +public interface J2 : J1 { + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} 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 cca6c299fea..59527912ef1 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 @@ -636,6 +636,18 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/AnnotatedBoundsOfWildcard.fir.kt"); } + @Test + @TestMetadata("Captured.kt") + public void testCaptured() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.kt"); + } + + @Test + @TestMetadata("Captured.fir.kt") + public void testCaptured_fir() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.fir.kt"); + } + @Test @TestMetadata("Defaults.kt") public void testDefaults() throws Exception { @@ -784,6 +796,18 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/AnnotatedBoundsOfWildcard.fir.kt"); } + @Test + @TestMetadata("Captured.kt") + public void testCaptured() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.kt"); + } + + @Test + @TestMetadata("Captured.fir.kt") + public void testCaptured_fir() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.fir.kt"); + } + @Test @TestMetadata("Defaults.kt") public void testDefaults() 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 c0bbf6c4586..b2a47a62f45 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 @@ -636,6 +636,18 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/AnnotatedBoundsOfWildcard.fir.kt"); } + @Test + @TestMetadata("Captured.kt") + public void testCaptured() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.kt"); + } + + @Test + @TestMetadata("Captured.fir.kt") + public void testCaptured_fir() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.fir.kt"); + } + @Test @TestMetadata("Defaults.kt") public void testDefaults() throws Exception { @@ -784,6 +796,18 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/AnnotatedBoundsOfWildcard.fir.kt"); } + @Test + @TestMetadata("Captured.kt") + public void testCaptured() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.kt"); + } + + @Test + @TestMetadata("Captured.fir.kt") + public void testCaptured_fir() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.fir.kt"); + } + @Test @TestMetadata("Defaults.kt") public void testDefaults() 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 3769a9a6ca3..53a0c9d701b 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 @@ -636,6 +636,18 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/AnnotatedBoundsOfWildcard.fir.kt"); } + @Test + @TestMetadata("Captured.kt") + public void testCaptured() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.kt"); + } + + @Test + @TestMetadata("Captured.fir.kt") + public void testCaptured_fir() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/Captured.fir.kt"); + } + @Test @TestMetadata("Defaults.kt") public void testDefaults() throws Exception { @@ -784,6 +796,18 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/AnnotatedBoundsOfWildcard.fir.kt"); } + @Test + @TestMetadata("Captured.kt") + public void testCaptured() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.kt"); + } + + @Test + @TestMetadata("Captured.fir.kt") + public void testCaptured_fir() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/Captured.fir.kt"); + } + @Test @TestMetadata("Defaults.kt") public void testDefaults() throws Exception { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeWithEnhancement.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeWithEnhancement.kt index 2140ff5dcf0..e05001bbfa1 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeWithEnhancement.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeWithEnhancement.kt @@ -159,7 +159,7 @@ fun UnwrappedType.wrapEnhancement(enhancement: KotlinType?): UnwrappedType { if (this is TypeWithEnhancement) { return origin.wrapEnhancement(enhancement) } - if (enhancement == null) { + if (enhancement == null || enhancement == this) { return this } return when (this) {