From d047db850f772f772f837d0a364d1be355326f32 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Mon, 29 Jan 2024 15:06:00 +0100 Subject: [PATCH] [FIR] Fix nullability of function type created from custom function type #KT-64706 Fixed --- .../kotlin/fir/types/FunctionalTypeUtils.kt | 2 +- ...leComposableParameterAcrossModules.fir.txt | 18 +++++++++++++ ...ullableComposableParameterAcrossModules.kt | 25 +++++++++++++++++++ ...reePluginBlackBoxCodegenTestGenerated.java | 6 +++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 plugins/fir-plugin-prototype/testData/box/nullableComposableParameterAcrossModules.fir.txt create mode 100644 plugins/fir-plugin-prototype/testData/box/nullableComposableParameterAcrossModules.kt diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/FunctionalTypeUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/FunctionalTypeUtils.kt index e30dcd2d3e5..0010ebe33d8 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/FunctionalTypeUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/FunctionalTypeUtils.kt @@ -113,7 +113,7 @@ private fun ConeKotlinType.createFunctionTypeWithNewKind(session: FirSession, ki val functionTypeId = ClassId(kind.packageFqName, kind.numberedClassName(expandedType.typeArguments.size - 1)) return functionTypeId.toLookupTag().constructClassType( expandedType.typeArguments, - isNullable = false, + isNullable = expandedType.isNullable, attributes = expandedType.attributes ) } diff --git a/plugins/fir-plugin-prototype/testData/box/nullableComposableParameterAcrossModules.fir.txt b/plugins/fir-plugin-prototype/testData/box/nullableComposableParameterAcrossModules.fir.txt new file mode 100644 index 00000000000..f471c68b9ad --- /dev/null +++ b/plugins/fir-plugin-prototype/testData/box/nullableComposableParameterAcrossModules.fir.txt @@ -0,0 +1,18 @@ +Module: a +FILE: a.kt + public final fun RMenuItem(onClick: R|(() -> kotlin/Unit)?| = Null(null), trailing: R|@R|org/jetbrains/kotlin/fir/plugin/MyComposable|() some/MyComposableFunction0?| = Null(null)): R|kotlin/Unit| { + } +Module: b +FILE: b.kt + public final fun bar(onClick: R|(() -> kotlin/Unit)?| = Null(null)): R|kotlin/Unit| { + R|/RMenuItem|(onClick = R|/onClick|, trailing = R|/onClick|?.{ $subj$.R|kotlin/let| kotlin/Unit|, R|@R|org/jetbrains/kotlin/fir/plugin/MyComposable|() some/MyComposableFunction0?|>( = let@fun (it: R|() -> kotlin/Unit|): R|@R|org/jetbrains/kotlin/fir/plugin/MyComposable|() some/MyComposableFunction0?| { + ^ let@fun (): R|kotlin/Unit| { + ^@let Unit + } + + } + ) }) + } + public final fun box(): R|kotlin/String| { + ^box String(OK) + } diff --git a/plugins/fir-plugin-prototype/testData/box/nullableComposableParameterAcrossModules.kt b/plugins/fir-plugin-prototype/testData/box/nullableComposableParameterAcrossModules.kt new file mode 100644 index 00000000000..7511bd8416f --- /dev/null +++ b/plugins/fir-plugin-prototype/testData/box/nullableComposableParameterAcrossModules.kt @@ -0,0 +1,25 @@ +// ISSUE: KT-64994 + +// MODULE: a +// FILE: a.kt +import org.jetbrains.kotlin.fir.plugin.MyComposable + +fun RMenuItem( + onClick: (() -> Unit)? = null, + trailing: (@MyComposable () -> Unit)? = null, +) {} + +// MODULE: b(a) +// FILE: b.kt +import org.jetbrains.kotlin.fir.plugin.MyComposable + +fun bar(onClick: (() -> Unit)? = null) { + RMenuItem( + onClick = onClick, + trailing = onClick?.let { + { } + } + ) +} + +fun box() = "OK" \ No newline at end of file diff --git a/plugins/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/runners/FirLightTreePluginBlackBoxCodegenTestGenerated.java b/plugins/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/runners/FirLightTreePluginBlackBoxCodegenTestGenerated.java index f709e6a248b..cf21cce9983 100644 --- a/plugins/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/runners/FirLightTreePluginBlackBoxCodegenTestGenerated.java +++ b/plugins/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/runners/FirLightTreePluginBlackBoxCodegenTestGenerated.java @@ -97,6 +97,12 @@ public class FirLightTreePluginBlackBoxCodegenTestGenerated extends AbstractFirL runTest("plugins/fir-plugin-prototype/testData/box/newSupertype.kt"); } + @Test + @TestMetadata("nullableComposableParameterAcrossModules.kt") + public void testNullableComposableParameterAcrossModules() throws Exception { + runTest("plugins/fir-plugin-prototype/testData/box/nullableComposableParameterAcrossModules.kt"); + } + @Test @TestMetadata("replaceActualFunctionBodyWitExpectDefaultValue.kt") public void testReplaceActualFunctionBodyWitExpectDefaultValue() throws Exception {