diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 092d26c0566..c347668abcc 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -46301,6 +46301,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt"); } + @Test + @TestMetadata("kt50949_suspendConversionForExtensionFunction.kt") + public void testKt50949_suspendConversionForExtensionFunction() throws Exception { + runTest("compiler/testData/codegen/box/suspendConversion/kt50949_suspendConversionForExtensionFunction.kt"); + } + @Test @TestMetadata("overloadResolutionBySuspendModifier.kt") public void testOverloadResolutionBySuspendModifier() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java index 74e4bbd0604..b8182758e7e 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java @@ -1892,6 +1892,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/expressions/stringTemplates.kt"); } + @Test + @TestMetadata("suspendConversionForExtensionFunction.kt") + public void testSuspendConversionForExtensionFunction() throws Exception { + runTest("compiler/testData/ir/irText/expressions/suspendConversionForExtensionFunction.kt"); + } + @Test @TestMetadata("suspendConversionInVararg.kt") public void testSuspendConversionInVararg() throws Exception { diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt index a67371276f7..68f8bcec005 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt @@ -578,9 +578,9 @@ fun StatementGenerator.pregenerateExtensionInvokeCall(resolvedCall: ResolvedCall ExtensionInvokeCallReceiver(call, functionReceiverValue, extensionInvokeReceiverValue) call.irValueArgumentsByIndex[0] = null - resolvedCall.valueArgumentsByIndex!!.forEachIndexed { index, valueArgument -> - val valueParameter = call.descriptor.valueParameters[index] - call.irValueArgumentsByIndex[index + 1] = generateValueArgument(valueArgument, valueParameter, resolvedCall) + for ((valueParameter, valueArgument) in resolvedCall.valueArguments) { + call.irValueArgumentsByIndex[valueParameter.index + 1] = + generateValueArgument(valueArgument, valueParameter, resolvedCall) } return call diff --git a/compiler/testData/codegen/box/suspendConversion/kt50949_suspendConversionForExtensionFunction.kt b/compiler/testData/codegen/box/suspendConversion/kt50949_suspendConversionForExtensionFunction.kt new file mode 100644 index 00000000000..7bdf872c677 --- /dev/null +++ b/compiler/testData/codegen/box/suspendConversion/kt50949_suspendConversionForExtensionFunction.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: +SuspendConversion +// IGNORE_BACKEND: JVM + +fun box(): String { + val foo: String.(suspend () -> Unit) -> String = { this } + val f: () -> Unit = {} + return "OK".foo(f) +} diff --git a/compiler/testData/ir/irText/expressions/suspendConversionForExtensionFunction.fir.ir.txt b/compiler/testData/ir/irText/expressions/suspendConversionForExtensionFunction.fir.ir.txt new file mode 100644 index 00000000000..e9c17f095ad --- /dev/null +++ b/compiler/testData/ir/irText/expressions/suspendConversionForExtensionFunction.fir.ir.txt @@ -0,0 +1,28 @@ +FILE fqName: fileName:/suspendConversionForExtensionFunction.kt + FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + VAR name:foo type:@[ExtensionFunctionType] kotlin.Function2, kotlin.Unit> [val] + FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function2, kotlin.Unit> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.String, it:kotlin.coroutines.SuspendFunction0) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:kotlin.String + VALUE_PARAMETER name:it index:0 type:kotlin.coroutines.SuspendFunction0 + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (it: kotlin.coroutines.SuspendFunction0): kotlin.Unit declared in .main' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + VAR name:f type:kotlin.Function0 [val] + FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .main' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + CALL 'public abstract fun invoke (p1: P1 of kotlin.Function2, p2: P2 of kotlin.Function2): R of kotlin.Function2 [operator] declared in kotlin.Function2' type=kotlin.Unit origin=INVOKE + $this: GET_VAR 'val foo: @[ExtensionFunctionType] kotlin.Function2, kotlin.Unit> [val] declared in .main' type=@[ExtensionFunctionType] kotlin.Function2, kotlin.Unit> origin=VARIABLE_AS_FUNCTION + p1: CONST String type=kotlin.String value="" + p2: BLOCK type=kotlin.coroutines.SuspendFunction0 origin=SUSPEND_CONVERSION + FUN ADAPTER_FOR_SUSPEND_CONVERSION name:suspendConversion visibility:local modality:FINAL <> ($receiver:kotlin.Function0) returnType:kotlin.Unit [suspend] + $receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION name:callee type:kotlin.Function0 + BLOCK_BODY + CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=kotlin.Unit origin=null + $this: GET_VAR 'callee: kotlin.Function0 declared in .main.suspendConversion' type=kotlin.Function0 origin=null + FUNCTION_REFERENCE 'local final fun suspendConversion (): kotlin.Unit [suspend] declared in .main' type=kotlin.coroutines.SuspendFunction0 origin=SUSPEND_CONVERSION reflectionTarget=null + $receiver: GET_VAR 'val f: kotlin.Function0 [val] declared in .main' type=kotlin.Function0 origin=null diff --git a/compiler/testData/ir/irText/expressions/suspendConversionForExtensionFunction.ir.txt b/compiler/testData/ir/irText/expressions/suspendConversionForExtensionFunction.ir.txt new file mode 100644 index 00000000000..8c71c2ff2fd --- /dev/null +++ b/compiler/testData/ir/irText/expressions/suspendConversionForExtensionFunction.ir.txt @@ -0,0 +1,28 @@ +FILE fqName: fileName:/suspendConversionForExtensionFunction.kt + FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + VAR name:foo type:@[ExtensionFunctionType] kotlin.Function2, kotlin.Unit> [val] + FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function2, kotlin.Unit> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.String, it:kotlin.coroutines.SuspendFunction0) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name:$this$null type:kotlin.String + VALUE_PARAMETER name:it index:0 type:kotlin.coroutines.SuspendFunction0 + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (it: kotlin.coroutines.SuspendFunction0): kotlin.Unit declared in .main' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + VAR name:f type:kotlin.Function0 [val] + FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .main' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + CALL 'public abstract fun invoke (p1: P1 of kotlin.Function2, p2: P2 of kotlin.Function2): R of kotlin.Function2 [operator] declared in kotlin.Function2' type=kotlin.Unit origin=INVOKE + $this: GET_VAR 'val foo: @[ExtensionFunctionType] kotlin.Function2, kotlin.Unit> [val] declared in .main' type=@[ExtensionFunctionType] kotlin.Function2, kotlin.Unit> origin=VARIABLE_AS_FUNCTION + p1: CONST String type=kotlin.String value="" + p2: BLOCK type=kotlin.coroutines.SuspendFunction0 origin=SUSPEND_CONVERSION + FUN ADAPTER_FOR_SUSPEND_CONVERSION name:suspendConversion0 visibility:local modality:FINAL <> ($receiver:kotlin.Function0) returnType:kotlin.Unit [suspend] + $receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION name:callee type:kotlin.Function0 + BLOCK_BODY + CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=kotlin.Unit origin=null + $this: GET_VAR 'callee: kotlin.Function0 declared in .main.suspendConversion0' type=kotlin.Function0 origin=null + FUNCTION_REFERENCE 'local final fun suspendConversion0 (): kotlin.Unit [suspend] declared in .main' type=kotlin.coroutines.SuspendFunction0 origin=SUSPEND_CONVERSION reflectionTarget=null + $receiver: GET_VAR 'val f: kotlin.Function0 [val] declared in .main' type=kotlin.Function0 origin=null diff --git a/compiler/testData/ir/irText/expressions/suspendConversionForExtensionFunction.kt b/compiler/testData/ir/irText/expressions/suspendConversionForExtensionFunction.kt new file mode 100644 index 00000000000..b42f88b5d52 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/suspendConversionForExtensionFunction.kt @@ -0,0 +1,8 @@ +// SKIP_KT_DUMP +// !LANGUAGE: +SuspendConversion + +fun main() { + val foo: String.(suspend () -> Unit) -> Unit = {} + val f: () -> Unit = {} + "".foo(f) +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index a06a34609ea..8840ff41228 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -45761,6 +45761,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt"); } + @Test + @TestMetadata("kt50949_suspendConversionForExtensionFunction.kt") + public void testKt50949_suspendConversionForExtensionFunction() throws Exception { + runTest("compiler/testData/codegen/box/suspendConversion/kt50949_suspendConversionForExtensionFunction.kt"); + } + @Test @TestMetadata("overloadResolutionBySuspendModifier.kt") public void testOverloadResolutionBySuspendModifier() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 51c0d2ebce0..ce482556508 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -46301,6 +46301,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt"); } + @Test + @TestMetadata("kt50949_suspendConversionForExtensionFunction.kt") + public void testKt50949_suspendConversionForExtensionFunction() throws Exception { + runTest("compiler/testData/codegen/box/suspendConversion/kt50949_suspendConversionForExtensionFunction.kt"); + } + @Test @TestMetadata("overloadResolutionBySuspendModifier.kt") public void testOverloadResolutionBySuspendModifier() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java index b89bcefcb4c..d2c6a4bb80d 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java @@ -1892,6 +1892,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest { runTest("compiler/testData/ir/irText/expressions/stringTemplates.kt"); } + @Test + @TestMetadata("suspendConversionForExtensionFunction.kt") + public void testSuspendConversionForExtensionFunction() throws Exception { + runTest("compiler/testData/ir/irText/expressions/suspendConversionForExtensionFunction.kt"); + } + @Test @TestMetadata("suspendConversionInVararg.kt") public void testSuspendConversionInVararg() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index e9f0c9df81a..a26d694d57b 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -37065,6 +37065,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt"); } + @TestMetadata("kt50949_suspendConversionForExtensionFunction.kt") + public void ignoreKt50949_suspendConversionForExtensionFunction() throws Exception { + runTest("compiler/testData/codegen/box/suspendConversion/kt50949_suspendConversionForExtensionFunction.kt"); + } + @TestMetadata("overloadResolutionBySuspendModifier.kt") public void ignoreOverloadResolutionBySuspendModifier() throws Exception { runTest("compiler/testData/codegen/box/suspendConversion/overloadResolutionBySuspendModifier.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java index ed70e71073a..fe3cb3c8b8d 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java @@ -1402,6 +1402,11 @@ public class KlibTextTestCaseGenerated extends AbstractKlibTextTestCase { runTest("compiler/testData/ir/irText/expressions/stringTemplates.kt"); } + @TestMetadata("suspendConversionForExtensionFunction.kt") + public void testSuspendConversionForExtensionFunction() throws Exception { + runTest("compiler/testData/ir/irText/expressions/suspendConversionForExtensionFunction.kt"); + } + @TestMetadata("suspendConversionInVararg.kt") public void testSuspendConversionInVararg() throws Exception { runTest("compiler/testData/ir/irText/expressions/suspendConversionInVararg.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index cc1d3854811..f110f20d811 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -33577,6 +33577,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt"); } + @Test + @TestMetadata("kt50949_suspendConversionForExtensionFunction.kt") + public void testKt50949_suspendConversionForExtensionFunction() throws Exception { + runTest("compiler/testData/codegen/box/suspendConversion/kt50949_suspendConversionForExtensionFunction.kt"); + } + @Test @TestMetadata("overloadResolutionBySuspendModifier.kt") public void testOverloadResolutionBySuspendModifier() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index cdf7fdb4f78..dbe64716a9a 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -33679,6 +33679,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt"); } + @Test + @TestMetadata("kt50949_suspendConversionForExtensionFunction.kt") + public void testKt50949_suspendConversionForExtensionFunction() throws Exception { + runTest("compiler/testData/codegen/box/suspendConversion/kt50949_suspendConversionForExtensionFunction.kt"); + } + @Test @TestMetadata("overloadResolutionBySuspendModifier.kt") public void testOverloadResolutionBySuspendModifier() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 538740f1374..3581b6f8606 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -28120,6 +28120,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt"); } + @TestMetadata("kt50949_suspendConversionForExtensionFunction.kt") + public void testKt50949_suspendConversionForExtensionFunction() throws Exception { + runTest("compiler/testData/codegen/box/suspendConversion/kt50949_suspendConversionForExtensionFunction.kt"); + } + @TestMetadata("overloadResolutionBySuspendModifier.kt") public void testOverloadResolutionBySuspendModifier() throws Exception { runTest("compiler/testData/codegen/box/suspendConversion/overloadResolutionBySuspendModifier.kt"); diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index 26cbeb8100a..198639eac1a 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -36646,6 +36646,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt"); } + @Test + @TestMetadata("kt50949_suspendConversionForExtensionFunction.kt") + public void testKt50949_suspendConversionForExtensionFunction() throws Exception { + runTest("compiler/testData/codegen/box/suspendConversion/kt50949_suspendConversionForExtensionFunction.kt"); + } + @Test @TestMetadata("overloadResolutionBySuspendModifier.kt") public void testOverloadResolutionBySuspendModifier() throws Exception {