diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/kt47899.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/kt47899.kt new file mode 100644 index 00000000000..5241faec862 --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/kt47899.kt @@ -0,0 +1,15 @@ +// JSPECIFY_STATE: warn + +// FILE: Foo.java +import org.jspecify.nullness.Nullable; + +public class Foo { + public static void gauge(@Nullable T stateObject) {} +} + +// FILE: main.kt +fun test(metric: T) { + if (metric is String) { + Foo.gauge(metric) + } +} 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 8922bd48281..cca6c299fea 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 @@ -808,6 +808,12 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/IgnoreAnnotations.fir.kt"); } + @Test + @TestMetadata("kt47899.kt") + public void testKt47899() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/kt47899.kt"); + } + @Test @TestMetadata("NonPlatformTypeParameter.kt") public void testNonPlatformTypeParameter() 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 154c1b4c138..c0bbf6c4586 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 @@ -808,6 +808,12 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/IgnoreAnnotations.fir.kt"); } + @Test + @TestMetadata("kt47899.kt") + public void testKt47899() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/kt47899.kt"); + } + @Test @TestMetadata("NonPlatformTypeParameter.kt") public void testNonPlatformTypeParameter() 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 ab31aabf51a..3769a9a6ca3 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 @@ -808,6 +808,12 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/IgnoreAnnotations.fir.kt"); } + @Test + @TestMetadata("kt47899.kt") + public void testKt47899() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/warnMode/kt47899.kt"); + } + @Test @TestMetadata("NonPlatformTypeParameter.kt") public void testNonPlatformTypeParameter() 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 5e5eb575b7f..2afbbecfd91 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeWithEnhancement.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeWithEnhancement.kt @@ -144,6 +144,9 @@ fun KotlinType.unwrapEnhancementDeeply() = getEnhancementDeeply() ?: this fun KotlinType.unwrapEnhancement(): KotlinType = getEnhancement() ?: this +fun UnwrappedType.inheritEnhancement(origin: KotlinType, transform: (KotlinType) -> KotlinType): UnwrappedType = + wrapEnhancement(origin.getEnhancement()?.let(transform)) + fun UnwrappedType.inheritEnhancement(origin: KotlinType): UnwrappedType = wrapEnhancement(origin.getEnhancement()) fun UnwrappedType.wrapEnhancement(enhancement: KotlinType?): UnwrappedType { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/KotlinTypePreparator.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/KotlinTypePreparator.kt index 4117923a8b9..bd23141d910 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/KotlinTypePreparator.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/KotlinTypePreparator.kt @@ -68,7 +68,7 @@ abstract class KotlinTypePreparator : AbstractTypePreparator { unwrappedType } } - }.inheritEnhancement(unwrappedType) + }.inheritEnhancement(unwrappedType, ::prepareType) } object Default : KotlinTypePreparator()