From 923837f26bd583895dbf6f4e5bb20e2306717da1 Mon Sep 17 00:00:00 2001 From: pyos Date: Fri, 2 Dec 2022 10:02:06 +0100 Subject: [PATCH] FIR: keep nullability when serializing suspend function types No clue where to put the test for that since diagnostic tests, even multi-module ones, never touch the metadata serializer. So the test is a bytecode text one pretending to be about nullability annotations even though it also affects what resolution in another module will do. --- .../nullabilityAnnotations/suspendFunction.kt | 11 +++++++++++ .../nullabilityAnnotations/suspendFunction.txt | 13 +++++++++++++ ...r2IrSpecificBytecodeListingTestGenerated.java | 16 ++++++++++++++++ .../jetbrains/kotlin/fir/types/InferenceUtils.kt | 2 +- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 compiler/fir/fir2ir/testData/codegen/bytecodeListing/nullabilityAnnotations/suspendFunction.kt create mode 100644 compiler/fir/fir2ir/testData/codegen/bytecodeListing/nullabilityAnnotations/suspendFunction.txt diff --git a/compiler/fir/fir2ir/testData/codegen/bytecodeListing/nullabilityAnnotations/suspendFunction.kt b/compiler/fir/fir2ir/testData/codegen/bytecodeListing/nullabilityAnnotations/suspendFunction.kt new file mode 100644 index 00000000000..5c52b2e9ca9 --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/bytecodeListing/nullabilityAnnotations/suspendFunction.kt @@ -0,0 +1,11 @@ +// MODULE: lib +// FILE: 1.kt +interface I { + fun foo(x: (suspend () -> Unit)?): (suspend () -> Unit)? +} + +// MODULE: main(lib) +// FILE: 2.kt +class C : I { + override fun foo(x: (suspend () -> Unit)?) = x +} diff --git a/compiler/fir/fir2ir/testData/codegen/bytecodeListing/nullabilityAnnotations/suspendFunction.txt b/compiler/fir/fir2ir/testData/codegen/bytecodeListing/nullabilityAnnotations/suspendFunction.txt new file mode 100644 index 00000000000..4a6ff118dbb --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/bytecodeListing/nullabilityAnnotations/suspendFunction.txt @@ -0,0 +1,13 @@ +Module: lib +@kotlin.Metadata +public interface I { + // source: '1.kt' + public abstract @org.jetbrains.annotations.Nullable method foo(@org.jetbrains.annotations.Nullable p0: kotlin.jvm.functions.Function1): kotlin.jvm.functions.Function1 +} +Module: main +@kotlin.Metadata +public final class C { + // source: '2.kt' + public method (): void + public @org.jetbrains.annotations.Nullable method foo(@org.jetbrains.annotations.Nullable p0: kotlin.jvm.functions.Function1): kotlin.jvm.functions.Function1 +} diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/Fir2IrSpecificBytecodeListingTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/Fir2IrSpecificBytecodeListingTestGenerated.java index c44fcfd2500..2d7fa00473c 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/Fir2IrSpecificBytecodeListingTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/Fir2IrSpecificBytecodeListingTestGenerated.java @@ -25,6 +25,22 @@ public class Fir2IrSpecificBytecodeListingTestGenerated extends AbstractFirBytec KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/fir2ir/testData/codegen/bytecodeListing"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Nested + @TestMetadata("compiler/fir/fir2ir/testData/codegen/bytecodeListing/nullabilityAnnotations") + @TestDataPath("$PROJECT_ROOT") + public class NullabilityAnnotations { + @Test + public void testAllFilesPresentInNullabilityAnnotations() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/fir2ir/testData/codegen/bytecodeListing/nullabilityAnnotations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/bytecodeListing/nullabilityAnnotations/suspendFunction.kt"); + } + } + @Nested @TestMetadata("compiler/fir/fir2ir/testData/codegen/bytecodeListing/properties") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/InferenceUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/InferenceUtils.kt index 5de539a5391..850091b6ffb 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/InferenceUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/InferenceUtils.kt @@ -127,7 +127,7 @@ fun ConeKotlinType.suspendFunctionTypeToFunctionTypeWithContinuation(session: Fi arrayOf(lastTypeArgument), isNullable = false ) + lastTypeArgument).toTypedArray(), - isNullable = false, + isNullable = fullyExpandedType.isNullable, attributes = fullyExpandedType.attributes ) }