From 8bdb8ba232735bf97e75a33b449bdd0ca0e910ff Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 31 Aug 2022 15:07:26 +0200 Subject: [PATCH] K2: Fix type-alias expansion during suspend function type serialization When suspend function type is serialized, there is special logic that adds Continuation parameter, before doing so, type-aliases has to be expanded, attributes for resulting type should also derive from expanded type KT-53193, KT-54062 --- .../kotlin/fir/FirLoadCompiledKotlinGenerated.java | 5 +++++ .../coroutines/TypeAliasFTSuspendWithReceiver.txt | 9 +++++++++ .../src/org/jetbrains/kotlin/fir/types/InferenceUtils.kt | 2 +- .../coroutines/TypeAliasFTSuspendWithReceiver.kt | 9 +++++++++ .../coroutines/TypeAliasFTSuspendWithReceiver.txt | 8 ++++++++ .../kotlin/jvm/compiler/LoadJavaTestGenerated.java | 5 +++++ .../compiler/LoadKotlinWithTypeTableTestGenerated.java | 5 +++++ .../kotlin/jvm/compiler/ir/IrLoadJavaTestGenerated.java | 5 +++++ .../compiler/javac/LoadJavaUsingJavacTestGenerated.java | 5 +++++ .../runtime/JvmRuntimeDescriptorLoaderTestGenerated.java | 5 +++++ 10 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 compiler/fir/analysis-tests/testData/loadCompiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.txt create mode 100644 compiler/testData/loadJava/compiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.kt create mode 100644 compiler/testData/loadJava/compiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.txt diff --git a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/FirLoadCompiledKotlinGenerated.java b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/FirLoadCompiledKotlinGenerated.java index 9f28f9c4807..f0f65e6dfc8 100644 --- a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/FirLoadCompiledKotlinGenerated.java +++ b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/FirLoadCompiledKotlinGenerated.java @@ -1000,6 +1000,11 @@ public class FirLoadCompiledKotlinGenerated extends AbstractFirLoadCompiledKotli public void testBasic() throws Exception { runTest("compiler/testData/loadJava/compiledKotlin/coroutines/Basic.kt"); } + + @TestMetadata("TypeAliasFTSuspendWithReceiver.kt") + public void testTypeAliasFTSuspendWithReceiver() throws Exception { + runTest("compiler/testData/loadJava/compiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.kt"); + } } @TestMetadata("compiler/testData/loadJava/compiledKotlin/dataClass") diff --git a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.txt b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.txt new file mode 100644 index 00000000000..543e6e98068 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.txt @@ -0,0 +1,9 @@ +public final fun foo(f: R|suspend test/Context.() -> kotlin/Unit|): R|kotlin/Unit| + +public final class Context : R|kotlin/Any| { + public constructor(): R|test/Context| + +} + +public final typealias SuspendWithContext = R|suspend test/Context.() -> kotlin/Unit| + 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 e7e43162466..2512a47d8d2 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 @@ -123,7 +123,7 @@ fun ConeKotlinType.suspendFunctionTypeToFunctionTypeWithContinuation(session: Fi isNullable = false ) + lastTypeArgument).toTypedArray(), isNullable = false, - attributes = attributes + attributes = fullyExpandedType.attributes ) } diff --git a/compiler/testData/loadJava/compiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.kt b/compiler/testData/loadJava/compiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.kt new file mode 100644 index 00000000000..19394a621d5 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.kt @@ -0,0 +1,9 @@ +// NO_CHECK_SOURCE_VS_BINARY +// Type-alias info is lost during serialization in K1 +package test + +class Context + +typealias SuspendWithContext = suspend Context.() -> Unit + +fun foo(f: SuspendWithContext) {} \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.txt b/compiler/testData/loadJava/compiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.txt new file mode 100644 index 00000000000..b319e284ce8 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.txt @@ -0,0 +1,8 @@ +package test + +public fun foo(/*0*/ f: suspend test.Context.() -> kotlin.Unit): kotlin.Unit + +public final class Context { + /*primary*/ public constructor Context() +} +public typealias SuspendWithContext = suspend test.Context.() -> kotlin.Unit diff --git a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java index cfdc068acd7..2cca4980846 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java @@ -2678,6 +2678,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { public void testBasic() throws Exception { runTest("compiler/testData/loadJava/compiledKotlin/coroutines/Basic.kt"); } + + @TestMetadata("TypeAliasFTSuspendWithReceiver.kt") + public void testTypeAliasFTSuspendWithReceiver() throws Exception { + runTest("compiler/testData/loadJava/compiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.kt"); + } } @TestMetadata("compiler/testData/loadJava/compiledKotlin/dataClass") diff --git a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java index 0d5f97d281a..cb3dd0b24dc 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java @@ -1000,6 +1000,11 @@ public class LoadKotlinWithTypeTableTestGenerated extends AbstractLoadKotlinWith public void testBasic() throws Exception { runTest("compiler/testData/loadJava/compiledKotlin/coroutines/Basic.kt"); } + + @TestMetadata("TypeAliasFTSuspendWithReceiver.kt") + public void testTypeAliasFTSuspendWithReceiver() throws Exception { + runTest("compiler/testData/loadJava/compiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.kt"); + } } @TestMetadata("compiler/testData/loadJava/compiledKotlin/dataClass") diff --git a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/ir/IrLoadJavaTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/ir/IrLoadJavaTestGenerated.java index 922edfb5020..3081237d691 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/ir/IrLoadJavaTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/ir/IrLoadJavaTestGenerated.java @@ -2679,6 +2679,11 @@ public class IrLoadJavaTestGenerated extends AbstractIrLoadJavaTest { public void testBasic() throws Exception { runTest("compiler/testData/loadJava/compiledKotlin/coroutines/Basic.kt"); } + + @TestMetadata("TypeAliasFTSuspendWithReceiver.kt") + public void testTypeAliasFTSuspendWithReceiver() throws Exception { + runTest("compiler/testData/loadJava/compiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.kt"); + } } @TestMetadata("compiler/testData/loadJava/compiledKotlin/dataClass") diff --git a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/javac/LoadJavaUsingJavacTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/javac/LoadJavaUsingJavacTestGenerated.java index 196b54237ce..2f94b3319de 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/javac/LoadJavaUsingJavacTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/jvm/compiler/javac/LoadJavaUsingJavacTestGenerated.java @@ -2678,6 +2678,11 @@ public class LoadJavaUsingJavacTestGenerated extends AbstractLoadJavaUsingJavacT public void testBasic() throws Exception { runTest("compiler/testData/loadJava/compiledKotlin/coroutines/Basic.kt"); } + + @TestMetadata("TypeAliasFTSuspendWithReceiver.kt") + public void testTypeAliasFTSuspendWithReceiver() throws Exception { + runTest("compiler/testData/loadJava/compiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.kt"); + } } @TestMetadata("compiler/testData/loadJava/compiledKotlin/dataClass") diff --git a/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java b/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java index 025ab0aa642..425b5036587 100644 --- a/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java +++ b/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java @@ -1002,6 +1002,11 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD public void testBasic() throws Exception { runTest("compiler/testData/loadJava/compiledKotlin/coroutines/Basic.kt"); } + + @TestMetadata("TypeAliasFTSuspendWithReceiver.kt") + public void testTypeAliasFTSuspendWithReceiver() throws Exception { + runTest("compiler/testData/loadJava/compiledKotlin/coroutines/TypeAliasFTSuspendWithReceiver.kt"); + } } @TestMetadata("compiler/testData/loadJava/compiledKotlin/dataClass")