From 6c994787b3b5d37330e83e4e3b3cb1c8995e12f3 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Tue, 10 May 2022 17:19:01 +0200 Subject: [PATCH] [FE 1.0] Don't expand type enhancement Actually shallow type enhancement is primary, it's more specific ^KT-50734 Fixed --- ...nAnnotationsCompiledJavaTestGenerated.java | 6 +++ ...dJavaWithPsiClassReadingTestGenerated.java | 6 +++ ...ignAnnotationsSourceJavaTestGenerated.java | 6 +++ .../tests/kt50734.fir.kt | 40 ++++++++++++++++++ .../foreignAnnotationsTests/tests/kt50734.kt | 41 +++++++++++++++++++ .../foreignAnnotationsTests/tests/kt50734.txt | 29 +++++++++++++ ...nAnnotationsCompiledJavaTestGenerated.java | 6 +++ ...dJavaWithPsiClassReadingTestGenerated.java | 6 +++ ...ignAnnotationsSourceJavaTestGenerated.java | 6 +++ .../kotlin/types/TypeSubstitutor.java | 2 +- 10 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.fir.kt create mode 100644 compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.kt create mode 100644 compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.txt 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..57f69eaccbe 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 @@ -98,6 +98,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated extends A runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt48316_multiModuleAnnotationDefault.kt"); } + @Test + @TestMetadata("kt50734.kt") + public void testKt50734() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.kt"); + } + @Test @TestMetadata("lombokSimple.kt") public void testLombokSimple() 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..08260de40c1 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 @@ -98,6 +98,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTest runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt48316_multiModuleAnnotationDefault.kt"); } + @Test + @TestMetadata("kt50734.kt") + public void testKt50734() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.kt"); + } + @Test @TestMetadata("lombokSimple.kt") public void testLombokSimple() 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..8a7c93d4a07 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 @@ -98,6 +98,12 @@ public class FirOldFrontendForeignAnnotationsSourceJavaTestGenerated extends Abs runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt48316_multiModuleAnnotationDefault.kt"); } + @Test + @TestMetadata("kt50734.kt") + public void testKt50734() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.kt"); + } + @Test @TestMetadata("lombokSimple.kt") public void testLombokSimple() throws Exception { diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.fir.kt new file mode 100644 index 00000000000..8d3ae46fc43 --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.fir.kt @@ -0,0 +1,40 @@ +// FILE: Supplier.java +import io.reactivex.rxjava3.annotations.NonNull; +import io.reactivex.rxjava3.annotations.Nullable; + +// Shown from RxJava for reference +@FunctionalInterface +public interface Supplier<@NonNull T> { + T get() throws Throwable; +} + +// FILE: Maybe.java +public abstract class Maybe { + public final void subscribe() {} +} + +// FILE: FromSupplier.java +import io.reactivex.rxjava3.annotations.NonNull; +import io.reactivex.rxjava3.annotations.Nullable; + +public class FromSupplier { + static <@NonNull T> Maybe fromSupplier3(Supplier supplier) { + return null; + } + static <@NonNull T> Maybe fromSupplier5(@NonNull Supplier supplier) { + return null; + } +} + +// FILE: main.kt +fun main() { + // No Warning + // In this case, we have nullable type enhancement + FromSupplier.fromSupplier3 { null } + .subscribe() + + // In this case, we have not-null type enhancement + // Warning: Type Mismatch: Required Boolean? found Nothing + FromSupplier.fromSupplier5 { null } + .subscribe() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.kt new file mode 100644 index 00000000000..e9e412c6b8f --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.kt @@ -0,0 +1,41 @@ + +// FILE: Supplier.java +import io.reactivex.rxjava3.annotations.NonNull; +import io.reactivex.rxjava3.annotations.Nullable; + +// Shown from RxJava for reference +@FunctionalInterface +public interface Supplier<@NonNull T> { + T get() throws Throwable; +} + +// FILE: Maybe.java +public abstract class Maybe { + public final void subscribe() {} +} + +// FILE: FromSupplier.java +import io.reactivex.rxjava3.annotations.NonNull; +import io.reactivex.rxjava3.annotations.Nullable; + +public class FromSupplier { + static <@NonNull T> Maybe fromSupplier3(Supplier supplier) { + return null; + } + static <@NonNull T> Maybe fromSupplier5(@NonNull Supplier supplier) { + return null; + } +} + +// FILE: main.kt +fun main() { + // No Warning + // In this case, we have nullable type enhancement + FromSupplier.fromSupplier3 { null } + .subscribe() + + // In this case, we have not-null type enhancement + // Warning: Type Mismatch: Required Boolean? found Nothing + FromSupplier.fromSupplier5 { null } + .subscribe() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.txt b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.txt new file mode 100644 index 00000000000..268b7aead04 --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.txt @@ -0,0 +1,29 @@ +package + +public fun main(): kotlin.Unit + +public open class FromSupplier { + public constructor FromSupplier() + 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 + public/*package*/ open fun fromSupplier3(/*0*/ supplier: Supplier!): Maybe! + public/*package*/ open fun fromSupplier5(/*0*/ @io.reactivex.rxjava3.annotations.NonNull supplier: @io.reactivex.rxjava3.annotations.NonNull Supplier!): Maybe! +} + +public abstract class Maybe { + public constructor Maybe() + 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 final fun subscribe(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +@FunctionalInterface /* annotation class not found */ public interface Supplier { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun get(): 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/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..04514fc79a5 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 @@ -98,6 +98,12 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt48316_multiModuleAnnotationDefault.kt"); } + @Test + @TestMetadata("kt50734.kt") + public void testKt50734() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.kt"); + } + @Test @TestMetadata("lombokSimple.kt") public void testLombokSimple() 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..1460d02b35e 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 @@ -98,6 +98,12 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt48316_multiModuleAnnotationDefault.kt"); } + @Test + @TestMetadata("kt50734.kt") + public void testKt50734() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.kt"); + } + @Test @TestMetadata("lombokSimple.kt") public void testLombokSimple() 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..4919fdad0fb 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 @@ -98,6 +98,12 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt48316_multiModuleAnnotationDefault.kt"); } + @Test + @TestMetadata("kt50734.kt") + public void testKt50734() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt50734.kt"); + } + @Test @TestMetadata("lombokSimple.kt") public void testLombokSimple() throws Exception { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java index 64cd86f498b..49f8622a8cc 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java @@ -193,7 +193,7 @@ public class TypeSubstitutor implements TypeSubstitutorMarker { KotlinType substitutedEnhancement = substitute(enhancement, originalProjection.getProjectionKind()); KotlinType resultingType = TypeWithEnhancementKt.wrapEnhancement( substitution.getType().unwrap(), - substitutedEnhancement instanceof TypeWithEnhancement ? ((TypeWithEnhancement) substitutedEnhancement).getEnhancement() : substitutedEnhancement + substitutedEnhancement ); return new TypeProjectionImpl(substitution.getProjectionKind(), resultingType);