From c7a96810bf7af0cd8ae241213b1c1fe3eb7cad17 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Thu, 23 Apr 2020 15:20:44 +0300 Subject: [PATCH] JVM: Suspend conversion for function references --- .../kotlin/codegen/JvmRuntimeTypes.kt | 5 +- .../binding/CodegenAnnotatingVisitor.java | 19 ++++- .../ir/FirBlackBoxCodegenTestGenerated.java | 78 +++++++++++++++++++ .../jvm/lower/AddContinuationLowering.kt | 48 +++++++----- .../adaptedWithCoercionToUnit.kt | 28 +++++++ .../adaptedWithDefaultArguments.kt | 24 ++++++ .../suspendConversion/adaptedWithVarargs.kt | 24 ++++++ .../suspendConversion/bound.kt | 30 +++++++ .../suspendConversion/crossInline.kt | 25 ++++++ .../inlineAdaptedWithCoercionToUnit.kt | 28 +++++++ .../inlineAdaptedWithDefaultArguments.kt | 24 ++++++ .../inlineAdaptedWithVarargs.kt | 24 ++++++ .../suspendConversion/inlineBound.kt | 34 ++++++++ .../suspendConversion/inlineSimple.kt | 27 +++++++ .../suspendConversion/inlineWithParameters.kt | 24 ++++++ .../suspendConversion/simple.kt | 22 ++++++ .../suspendConversion/withParameters.kt | 24 ++++++ .../equality/suspendConversion.kt | 53 +++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 78 +++++++++++++++++++ .../LightAnalysisModeTestGenerated.java | 78 +++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 78 +++++++++++++++++++ .../IrJsCodegenBoxTestGenerated.java | 68 ++++++++++++++++ .../semantics/JsCodegenBoxTestGenerated.java | 68 ++++++++++++++++ 23 files changed, 886 insertions(+), 25 deletions(-) create mode 100644 compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithCoercionToUnit.kt create mode 100644 compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithDefaultArguments.kt create mode 100644 compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithVarargs.kt create mode 100644 compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/bound.kt create mode 100644 compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/crossInline.kt create mode 100644 compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithCoercionToUnit.kt create mode 100644 compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithDefaultArguments.kt create mode 100644 compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithVarargs.kt create mode 100644 compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineBound.kt create mode 100644 compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineSimple.kt create mode 100644 compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineWithParameters.kt create mode 100644 compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/simple.kt create mode 100644 compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/withParameters.kt create mode 100644 compiler/testData/codegen/box/callableReference/equality/suspendConversion.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt index b4d75b88905..2481fba4830 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt @@ -136,7 +136,8 @@ class JvmRuntimeTypes( referencedFunction: FunctionDescriptor, anonymousFunctionDescriptor: AnonymousFunctionDescriptor, isBound: Boolean, - isAdaptedCallableReference: Boolean + isAdaptedCallableReference: Boolean, + isSuspendConversion: Boolean ): Collection { val receivers = computeExpectedNumberOfReceivers(referencedFunction, isBound) @@ -148,7 +149,7 @@ class JvmRuntimeTypes( anonymousFunctionDescriptor.valueParameters.drop(receivers).map { it.type }, null, anonymousFunctionDescriptor.returnType!!, - referencedFunction.isSuspend + referencedFunction.isSuspend || isSuspendConversion ) val suspendFunctionType = if (referencedFunction.isSuspend) suspendFunctionInterface?.defaultType else null diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java index 86542ca46d5..23735161f07 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java @@ -33,7 +33,6 @@ import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor; import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor; import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil; import org.jetbrains.kotlin.load.java.JvmAbi; -import org.jetbrains.kotlin.resolve.sam.SamConstructorDescriptor; import org.jetbrains.kotlin.name.ClassId; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.*; @@ -54,6 +53,7 @@ import org.jetbrains.kotlin.resolve.constants.EnumValue; import org.jetbrains.kotlin.resolve.constants.NullValue; import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt; import org.jetbrains.kotlin.resolve.jvm.RuntimeAssertionsOnDeclarationBodyChecker; +import org.jetbrains.kotlin.resolve.sam.SamConstructorDescriptor; import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver; @@ -360,8 +360,11 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid { private boolean isAdaptedCallableReference( @NotNull KtCallableReferenceExpression expression, - @NotNull ResolvedCall resolvedCall + @NotNull ResolvedCall resolvedCall, + boolean isSuspendConversion ) { + if (isSuspendConversion) return true; + CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor(); if (!(resultingDescriptor instanceof FunctionDescriptor)) return false; FunctionDescriptor functionDescriptor = (FunctionDescriptor) resultingDescriptor; @@ -401,12 +404,20 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid { Collection supertypes; if (target instanceof FunctionDescriptor) { + FunctionDescriptor targetFunction = (FunctionDescriptor) target; callableDescriptor = bindingContext.get(FUNCTION, expression); if (callableDescriptor == null) return; + KotlinType functionReferenceType = bindingContext.getType(expression); + boolean isSuspendConversion = + !targetFunction.isSuspend() && + functionReferenceType != null && + FunctionTypesKt.isKSuspendFunctionType(functionReferenceType); + supertypes = runtimeTypes.getSupertypesForFunctionReference( - (FunctionDescriptor) target, (AnonymousFunctionDescriptor) callableDescriptor, receiverType != null, - isAdaptedCallableReference(expression, referencedFunction) + targetFunction, (AnonymousFunctionDescriptor) callableDescriptor, receiverType != null, + isAdaptedCallableReference(expression, referencedFunction, isSuspendConversion), + isSuspendConversion ); } else if (target instanceof PropertyDescriptor) { diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index baeedb47d6d..2c44f5b9121 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -2114,6 +2114,84 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT public void testVarargWithDefaultValue() throws Exception { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/varargWithDefaultValue.kt"); } + + @TestMetadata("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class SuspendConversion extends AbstractFirBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: "); + } + + @TestMetadata("adaptedWithCoercionToUnit.kt") + public void testAdaptedWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithCoercionToUnit.kt"); + } + + @TestMetadata("adaptedWithDefaultArguments.kt") + public void testAdaptedWithDefaultArguments() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithDefaultArguments.kt"); + } + + @TestMetadata("adaptedWithVarargs.kt") + public void testAdaptedWithVarargs() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithVarargs.kt"); + } + + public void testAllFilesPresentInSuspendConversion() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @TestMetadata("bound.kt") + public void testBound() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/bound.kt"); + } + + @TestMetadata("crossInline.kt") + public void testCrossInline() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/crossInline.kt"); + } + + @TestMetadata("inlineAdaptedWithCoercionToUnit.kt") + public void testInlineAdaptedWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithCoercionToUnit.kt"); + } + + @TestMetadata("inlineAdaptedWithDefaultArguments.kt") + public void testInlineAdaptedWithDefaultArguments() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithDefaultArguments.kt"); + } + + @TestMetadata("inlineAdaptedWithVarargs.kt") + public void testInlineAdaptedWithVarargs() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithVarargs.kt"); + } + + @TestMetadata("inlineBound.kt") + public void testInlineBound() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineBound.kt"); + } + + @TestMetadata("inlineSimple.kt") + public void testInlineSimple() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineSimple.kt"); + } + + @TestMetadata("inlineWithParameters.kt") + public void testInlineWithParameters() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineWithParameters.kt"); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/simple.kt"); + } + + @TestMetadata("withParameters.kt") + public void testWithParameters() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/withParameters.kt"); + } + } } @TestMetadata("compiler/testData/codegen/box/callableReference/bound") diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt index 265cab8a0ef..40e2880ab4e 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt @@ -95,10 +95,13 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : override fun visitFunctionReference(expression: IrFunctionReference) { expression.acceptChildrenVoid(this) - if (expression.isSuspend && expression.origin == IrStatementOrigin.LAMBDA && expression !in inlineReferences) { + if (expression.isSuspend && expression.isLambdaOrAdaptedCallableReference() && expression !in inlineReferences) { suspendLambdas[expression] = SuspendLambdaInfo(expression) } } + + private fun IrFunctionReference.isLambdaOrAdaptedCallableReference() = + origin == IrStatementOrigin.LAMBDA || origin == IrStatementOrigin.ADAPTED_FUNCTION_REFERENCE }) for (lambda in suspendLambdas.values) { @@ -207,7 +210,11 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : } } - private fun IrClass.addInvokeSuspendForLambda(irFunction: IrFunction, fields: List, receiverField: IrField?): IrSimpleFunction { + private fun IrClass.addInvokeSuspendForLambda( + irFunction: IrFunction, + fields: List, + receiverField: IrField? + ): IrSimpleFunction { val superMethod = context.ir.symbols.suspendLambdaClass.functions.single { it.owner.name.asString() == INVOKE_SUSPEND_METHOD_NAME && it.owner.valueParameters.size == 1 && it.owner.valueParameters[0].type.isKotlinResult() @@ -425,24 +432,25 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : } } - private fun IrClass.addConstructorForNamedFunction(capturedThisField: IrField?, capturesCrossinline: Boolean): IrConstructor = addConstructor { - isPrimary = true - returnType = defaultType - visibility = if (capturesCrossinline) Visibilities.PUBLIC else JavaVisibilities.PACKAGE_VISIBILITY - }.also { constructor -> - val capturedThisParameter = capturedThisField?.let { constructor.addValueParameter(it.name.asString(), it.type) } - val completionParameterSymbol = constructor.addCompletionValueParameter() + private fun IrClass.addConstructorForNamedFunction(capturedThisField: IrField?, capturesCrossinline: Boolean): IrConstructor = + addConstructor { + isPrimary = true + returnType = defaultType + visibility = if (capturesCrossinline) Visibilities.PUBLIC else JavaVisibilities.PACKAGE_VISIBILITY + }.also { constructor -> + val capturedThisParameter = capturedThisField?.let { constructor.addValueParameter(it.name.asString(), it.type) } + val completionParameterSymbol = constructor.addCompletionValueParameter() - val superClassConstructor = context.ir.symbols.continuationImplClass.owner.constructors.single { it.valueParameters.size == 1 } - constructor.body = context.createIrBuilder(constructor.symbol).irBlockBody { - if (capturedThisField != null) { - +irSetField(irGet(thisReceiver!!), capturedThisField, irGet(capturedThisParameter!!)) - } - +irDelegatingConstructorCall(superClassConstructor).also { - it.putValueArgument(0, irGet(completionParameterSymbol)) + val superClassConstructor = context.ir.symbols.continuationImplClass.owner.constructors.single { it.valueParameters.size == 1 } + constructor.body = context.createIrBuilder(constructor.symbol).irBlockBody { + if (capturedThisField != null) { + +irSetField(irGet(thisReceiver!!), capturedThisField, irGet(capturedThisParameter!!)) + } + +irDelegatingConstructorCall(superClassConstructor).also { + it.putValueArgument(0, irGet(completionParameterSymbol)) + } } } - } private fun IrClass.addInvokeSuspendForNamedFunction( irFunction: IrFunction, @@ -708,8 +716,10 @@ private fun T.retargetToSuspendView( val continuation = if (caller.origin == IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA) context.fakeContinuation else - IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, caller.continuationParameter()?.symbol - ?: throw AssertionError("${caller.render()} has no continuation; can't call ${symbol.owner.render()}")) + IrGetValueImpl( + UNDEFINED_OFFSET, UNDEFINED_OFFSET, caller.continuationParameter()?.symbol + ?: throw AssertionError("${caller.render()} has no continuation; can't call ${symbol.owner.render()}") + ) it.putValueArgument(continuationIndex, continuation) } } diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithCoercionToUnit.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithCoercionToUnit.kt new file mode 100644 index 00000000000..e97a448df96 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithCoercionToUnit.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: +SuspendConversion +// WITH_RUNTIME +// WITH_COROUTINES +// IGNORE_BACKEND_FIR: JVM_IR + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +fun runSuspend(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +var test = "failed" + +fun foo(s: String): String { + test = s + "K" + return test +} + +suspend fun invokeSuspend(fn: suspend (String) -> Unit, arg: String) = fn.invoke(arg) + +fun box(): String { + runSuspend { + invokeSuspend(::foo, "O") + } + return test +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithDefaultArguments.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithDefaultArguments.kt new file mode 100644 index 00000000000..7891bfa5eea --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithDefaultArguments.kt @@ -0,0 +1,24 @@ +// !LANGUAGE: +SuspendConversion +// WITH_RUNTIME +// WITH_COROUTINES +// IGNORE_BACKEND_FIR: JVM_IR + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +fun runSuspend(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun foo(s1: String, s2: String = "K"): String = s1 + s2 + +suspend fun invokeSuspend(fn: suspend (String) -> String, arg: String) = fn.invoke(arg) + +fun box(): String { + var test = "failed" + runSuspend { + test = invokeSuspend(::foo, "O") + } + return test +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithVarargs.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithVarargs.kt new file mode 100644 index 00000000000..458f1c04fe8 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithVarargs.kt @@ -0,0 +1,24 @@ +// !LANGUAGE: +SuspendConversion +// WITH_RUNTIME +// WITH_COROUTINES +// IGNORE_BACKEND_FIR: JVM_IR + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +fun runSuspend(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun foo(vararg ss: String): String = ss[0] + "K" + +suspend fun invokeSuspend(fn: suspend (String) -> String, arg: String) = fn.invoke(arg) + +fun box(): String { + var test = "failed" + runSuspend { + test = invokeSuspend(::foo, "O") + } + return test +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/bound.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/bound.kt new file mode 100644 index 00000000000..f27ba87a7bf --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/bound.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +SuspendConversion +// WITH_RUNTIME +// WITH_COROUTINES +// IGNORE_BACKEND_FIR: JVM_IR +// TARGET_BACKEND: JVM +// ^ this test hangs on JS_IR (even if it's IGNOREd) +// IGNORE_BACKEND: JVM_IR + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + + +fun runSuspend(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +class C { + var test = "failed" + + fun foo() { + test = "OK" + } +} + +fun box(): String { + val c = C() + runSuspend(c::foo) + return c.test +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/crossInline.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/crossInline.kt new file mode 100644 index 00000000000..ef87d44e6f4 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/crossInline.kt @@ -0,0 +1,25 @@ +// !LANGUAGE: +SuspendConversion +// WITH_RUNTIME +// WITH_COROUTINES +// IGNORE_BACKEND_FIR: JVM_IR + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +fun runSuspend(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +var test = "failed" + +fun foo() { test = "OK" } + +inline suspend fun invokeSuspend(crossinline fn: suspend () -> Unit) = suspend { fn() } + +fun box(): String { + runSuspend { + invokeSuspend(::foo)() + } + return test +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithCoercionToUnit.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithCoercionToUnit.kt new file mode 100644 index 00000000000..36a28fe67e2 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithCoercionToUnit.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: +SuspendConversion +// WITH_RUNTIME +// WITH_COROUTINES +// IGNORE_BACKEND_FIR: JVM_IR + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +fun runSuspend(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +var test = "failed" + +fun foo(s: String): String { + test = s + "K" + return test +} + +inline suspend fun invokeSuspend(fn: suspend (String) -> Unit, arg: String) = fn.invoke(arg) + +fun box(): String { + runSuspend { + invokeSuspend(::foo, "O") + } + return test +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithDefaultArguments.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithDefaultArguments.kt new file mode 100644 index 00000000000..42682930938 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithDefaultArguments.kt @@ -0,0 +1,24 @@ +// !LANGUAGE: +SuspendConversion +// WITH_RUNTIME +// WITH_COROUTINES +// IGNORE_BACKEND_FIR: JVM_IR + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +fun runSuspend(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun foo(s1: String, s2: String = "K"): String = s1 + s2 + +inline suspend fun invokeSuspend(fn: suspend (String) -> String, arg: String) = fn.invoke(arg) + +fun box(): String { + var test = "failed" + runSuspend { + test = invokeSuspend(::foo, "O") + } + return test +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithVarargs.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithVarargs.kt new file mode 100644 index 00000000000..78d3289f5d5 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithVarargs.kt @@ -0,0 +1,24 @@ +// !LANGUAGE: +SuspendConversion +// WITH_RUNTIME +// WITH_COROUTINES +// IGNORE_BACKEND_FIR: JVM_IR + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +fun runSuspend(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun foo(vararg ss: String): String = ss[0] + "K" + +inline suspend fun invokeSuspend(fn: suspend (String) -> String, arg: String) = fn.invoke(arg) + +fun box(): String { + var test = "failed" + runSuspend { + test = invokeSuspend(::foo, "O") + } + return test +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineBound.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineBound.kt new file mode 100644 index 00000000000..24e135ee730 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineBound.kt @@ -0,0 +1,34 @@ +// !LANGUAGE: +SuspendConversion +// WITH_RUNTIME +// WITH_COROUTINES +// IGNORE_BACKEND_FIR: JVM_IR +// TARGET_BACKEND: JVM +// ^ this test hangs on JS_IR (even if it's IGNOREd) +// IGNORE_BACKEND: JVM_IR + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + + +fun runSuspend(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +inline suspend fun invokeSuspend(fn: suspend () -> Unit) = fn() + +class C { + var test = "failed" + + fun foo() { + test = "OK" + } +} + +fun box(): String { + val c = C() + runSuspend { + invokeSuspend(c::foo) + } + return c.test +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineSimple.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineSimple.kt new file mode 100644 index 00000000000..4ccba2c6065 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineSimple.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: +SuspendConversion +// WITH_RUNTIME +// WITH_COROUTINES +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JS + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + + +fun runSuspend(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +var test = "failed" + +fun foo() { test = "OK" } + +inline suspend fun invokeSuspend(fn: suspend () -> Unit) { fn() } + +fun box(): String { + runSuspend { + invokeSuspend(::foo) + } + return test +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineWithParameters.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineWithParameters.kt new file mode 100644 index 00000000000..799716a21ca --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineWithParameters.kt @@ -0,0 +1,24 @@ +// !LANGUAGE: +SuspendConversion +// WITH_RUNTIME +// WITH_COROUTINES +// IGNORE_BACKEND_FIR: JVM_IR + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +fun runSuspend(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun foo(s: String): String = s + "K" + +inline suspend fun invokeSuspend(fn: suspend (String) -> String, arg: String) = fn.invoke(arg) + +fun box(): String { + var test = "failed" + runSuspend { + test = invokeSuspend(::foo, "O") + } + return test +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/simple.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/simple.kt new file mode 100644 index 00000000000..a8861a1da8d --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/simple.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: +SuspendConversion +// WITH_RUNTIME +// WITH_COROUTINES +// IGNORE_BACKEND_FIR: JVM_IR + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + + +fun runSuspend(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +var test = "failed" + +fun foo() { test = "OK" } + +fun box(): String { + runSuspend(::foo) + return test +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/withParameters.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/withParameters.kt new file mode 100644 index 00000000000..17bb0549aec --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/withParameters.kt @@ -0,0 +1,24 @@ +// !LANGUAGE: +SuspendConversion +// WITH_RUNTIME +// WITH_COROUTINES +// IGNORE_BACKEND_FIR: JVM_IR + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +fun runSuspend(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun foo(s: String): String = s + "K" + +suspend fun invokeSuspend(fn: suspend (String) -> String, arg: String) = fn.invoke(arg) + +fun box(): String { + var test = "failed" + runSuspend { + test = invokeSuspend(::foo, "O") + } + return test +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/equality/suspendConversion.kt b/compiler/testData/codegen/box/callableReference/equality/suspendConversion.kt new file mode 100644 index 00000000000..8a862fccb95 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/equality/suspendConversion.kt @@ -0,0 +1,53 @@ +// !LANGUAGE: +SuspendConversion +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JVM_IR, JS_IR +// FILE: suspendCovnersion.kt + +fun checkNotEqual(x: Any, y: Any) { + if (x == y || y == x) throw AssertionError("$x and $y should NOT be equal") +} + +fun capturePlain(fn: () -> Unit): Any = fn +fun captureSuspend(fn: suspend () -> Unit): Any = fn +fun capturePlainInt(fn: (Int) -> Unit): Any = fn +fun captureSuspendInt(fn: suspend (Int) -> Unit): Any = fn + +fun foo() {} + +class C { + fun memberFun() {} +} + +fun fnWithVararg(vararg xs: Int) {} + +fun fnWithDefault(x1: Int = 1, x2: Int = 2) {} + +fun fnReturnsInt() = 1 + +fun box(): String { + val c = C() + + checkNotEqual(capturePlain(::foo), captureSuspend(::foo)) + checkNotEqual(capturePlain(c::memberFun), captureSuspend(c::memberFun)) + + checkNotEqual(captureOther1(), captureOther2()) + checkNotEqual(captureBoundOther1(c), captureBoundOther2(c)) + + checkNotEqual(capturePlainInt(::fnWithVararg), captureSuspendInt(::fnWithVararg)) + checkNotEqual(captureSuspend(::fnWithVararg), captureSuspendInt(::fnWithVararg)) + + checkNotEqual(capturePlainInt(::fnWithDefault), captureSuspendInt(::fnWithDefault)) + checkNotEqual(captureSuspend(::fnWithDefault), captureSuspendInt(::fnWithDefault)) + + checkNotEqual(capturePlain(::fnReturnsInt), captureSuspend(::fnReturnsInt)) + + return "OK" +} + +// FILE: fromOtherFile.kt + +fun captureOther1() = capturePlain(::foo) +fun captureOther2() = captureSuspend(::foo) + +fun captureBoundOther1(c: C) = capturePlain(c::memberFun) +fun captureBoundOther2(c: C) = captureSuspend(c::memberFun) \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 234e7f34659..b743bb6bfdc 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -2134,6 +2134,84 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testVarargWithDefaultValue() throws Exception { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/varargWithDefaultValue.kt"); } + + @TestMetadata("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class SuspendConversion extends AbstractBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + @TestMetadata("adaptedWithCoercionToUnit.kt") + public void testAdaptedWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithCoercionToUnit.kt"); + } + + @TestMetadata("adaptedWithDefaultArguments.kt") + public void testAdaptedWithDefaultArguments() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithDefaultArguments.kt"); + } + + @TestMetadata("adaptedWithVarargs.kt") + public void testAdaptedWithVarargs() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithVarargs.kt"); + } + + public void testAllFilesPresentInSuspendConversion() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @TestMetadata("bound.kt") + public void testBound() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/bound.kt"); + } + + @TestMetadata("crossInline.kt") + public void testCrossInline() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/crossInline.kt"); + } + + @TestMetadata("inlineAdaptedWithCoercionToUnit.kt") + public void testInlineAdaptedWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithCoercionToUnit.kt"); + } + + @TestMetadata("inlineAdaptedWithDefaultArguments.kt") + public void testInlineAdaptedWithDefaultArguments() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithDefaultArguments.kt"); + } + + @TestMetadata("inlineAdaptedWithVarargs.kt") + public void testInlineAdaptedWithVarargs() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithVarargs.kt"); + } + + @TestMetadata("inlineBound.kt") + public void testInlineBound() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineBound.kt"); + } + + @TestMetadata("inlineSimple.kt") + public void testInlineSimple() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineSimple.kt"); + } + + @TestMetadata("inlineWithParameters.kt") + public void testInlineWithParameters() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineWithParameters.kt"); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/simple.kt"); + } + + @TestMetadata("withParameters.kt") + public void testWithParameters() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/withParameters.kt"); + } + } } @TestMetadata("compiler/testData/codegen/box/callableReference/bound") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 0638978695e..f7c574d67a9 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -2134,6 +2134,84 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes public void testVarargWithDefaultValue() throws Exception { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/varargWithDefaultValue.kt"); } + + @TestMetadata("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class SuspendConversion extends AbstractLightAnalysisModeTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + @TestMetadata("adaptedWithCoercionToUnit.kt") + public void testAdaptedWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithCoercionToUnit.kt"); + } + + @TestMetadata("adaptedWithDefaultArguments.kt") + public void testAdaptedWithDefaultArguments() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithDefaultArguments.kt"); + } + + @TestMetadata("adaptedWithVarargs.kt") + public void testAdaptedWithVarargs() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithVarargs.kt"); + } + + public void testAllFilesPresentInSuspendConversion() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @TestMetadata("bound.kt") + public void testBound() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/bound.kt"); + } + + @TestMetadata("crossInline.kt") + public void testCrossInline() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/crossInline.kt"); + } + + @TestMetadata("inlineAdaptedWithCoercionToUnit.kt") + public void testInlineAdaptedWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithCoercionToUnit.kt"); + } + + @TestMetadata("inlineAdaptedWithDefaultArguments.kt") + public void testInlineAdaptedWithDefaultArguments() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithDefaultArguments.kt"); + } + + @TestMetadata("inlineAdaptedWithVarargs.kt") + public void testInlineAdaptedWithVarargs() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithVarargs.kt"); + } + + @TestMetadata("inlineBound.kt") + public void testInlineBound() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineBound.kt"); + } + + @TestMetadata("inlineSimple.kt") + public void testInlineSimple() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineSimple.kt"); + } + + @TestMetadata("inlineWithParameters.kt") + public void testInlineWithParameters() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineWithParameters.kt"); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/simple.kt"); + } + + @TestMetadata("withParameters.kt") + public void testWithParameters() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/withParameters.kt"); + } + } } @TestMetadata("compiler/testData/codegen/box/callableReference/bound") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index ff4392f7e9a..148bfea0eca 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -2114,6 +2114,84 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes public void testVarargWithDefaultValue() throws Exception { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/varargWithDefaultValue.kt"); } + + @TestMetadata("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class SuspendConversion extends AbstractIrBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + @TestMetadata("adaptedWithCoercionToUnit.kt") + public void testAdaptedWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithCoercionToUnit.kt"); + } + + @TestMetadata("adaptedWithDefaultArguments.kt") + public void testAdaptedWithDefaultArguments() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithDefaultArguments.kt"); + } + + @TestMetadata("adaptedWithVarargs.kt") + public void testAdaptedWithVarargs() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithVarargs.kt"); + } + + public void testAllFilesPresentInSuspendConversion() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @TestMetadata("bound.kt") + public void testBound() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/bound.kt"); + } + + @TestMetadata("crossInline.kt") + public void testCrossInline() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/crossInline.kt"); + } + + @TestMetadata("inlineAdaptedWithCoercionToUnit.kt") + public void testInlineAdaptedWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithCoercionToUnit.kt"); + } + + @TestMetadata("inlineAdaptedWithDefaultArguments.kt") + public void testInlineAdaptedWithDefaultArguments() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithDefaultArguments.kt"); + } + + @TestMetadata("inlineAdaptedWithVarargs.kt") + public void testInlineAdaptedWithVarargs() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithVarargs.kt"); + } + + @TestMetadata("inlineBound.kt") + public void testInlineBound() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineBound.kt"); + } + + @TestMetadata("inlineSimple.kt") + public void testInlineSimple() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineSimple.kt"); + } + + @TestMetadata("inlineWithParameters.kt") + public void testInlineWithParameters() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineWithParameters.kt"); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/simple.kt"); + } + + @TestMetadata("withParameters.kt") + public void testWithParameters() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/withParameters.kt"); + } + } } @TestMetadata("compiler/testData/codegen/box/callableReference/bound") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 255d8029256..0a8f4e744c5 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -1544,6 +1544,74 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { public void testVarargWithDefaultValue() throws Exception { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/varargWithDefaultValue.kt"); } + + @TestMetadata("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class SuspendConversion extends AbstractIrJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); + } + + @TestMetadata("adaptedWithCoercionToUnit.kt") + public void testAdaptedWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithCoercionToUnit.kt"); + } + + @TestMetadata("adaptedWithDefaultArguments.kt") + public void testAdaptedWithDefaultArguments() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithDefaultArguments.kt"); + } + + @TestMetadata("adaptedWithVarargs.kt") + public void testAdaptedWithVarargs() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithVarargs.kt"); + } + + public void testAllFilesPresentInSuspendConversion() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @TestMetadata("crossInline.kt") + public void testCrossInline() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/crossInline.kt"); + } + + @TestMetadata("inlineAdaptedWithCoercionToUnit.kt") + public void testInlineAdaptedWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithCoercionToUnit.kt"); + } + + @TestMetadata("inlineAdaptedWithDefaultArguments.kt") + public void testInlineAdaptedWithDefaultArguments() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithDefaultArguments.kt"); + } + + @TestMetadata("inlineAdaptedWithVarargs.kt") + public void testInlineAdaptedWithVarargs() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithVarargs.kt"); + } + + @TestMetadata("inlineSimple.kt") + public void testInlineSimple() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineSimple.kt"); + } + + @TestMetadata("inlineWithParameters.kt") + public void testInlineWithParameters() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineWithParameters.kt"); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/simple.kt"); + } + + @TestMetadata("withParameters.kt") + public void testWithParameters() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/withParameters.kt"); + } + } } @TestMetadata("compiler/testData/codegen/box/callableReference/bound") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 68c12d8b3df..9b8f18c3125 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -1544,6 +1544,74 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { public void testVarargWithDefaultValue() throws Exception { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/varargWithDefaultValue.kt"); } + + @TestMetadata("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class SuspendConversion extends AbstractJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath); + } + + @TestMetadata("adaptedWithCoercionToUnit.kt") + public void testAdaptedWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithCoercionToUnit.kt"); + } + + @TestMetadata("adaptedWithDefaultArguments.kt") + public void testAdaptedWithDefaultArguments() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithDefaultArguments.kt"); + } + + @TestMetadata("adaptedWithVarargs.kt") + public void testAdaptedWithVarargs() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/adaptedWithVarargs.kt"); + } + + public void testAllFilesPresentInSuspendConversion() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); + } + + @TestMetadata("crossInline.kt") + public void testCrossInline() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/crossInline.kt"); + } + + @TestMetadata("inlineAdaptedWithCoercionToUnit.kt") + public void testInlineAdaptedWithCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithCoercionToUnit.kt"); + } + + @TestMetadata("inlineAdaptedWithDefaultArguments.kt") + public void testInlineAdaptedWithDefaultArguments() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithDefaultArguments.kt"); + } + + @TestMetadata("inlineAdaptedWithVarargs.kt") + public void testInlineAdaptedWithVarargs() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithVarargs.kt"); + } + + @TestMetadata("inlineSimple.kt") + public void testInlineSimple() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineSimple.kt"); + } + + @TestMetadata("inlineWithParameters.kt") + public void testInlineWithParameters() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineWithParameters.kt"); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/simple.kt"); + } + + @TestMetadata("withParameters.kt") + public void testWithParameters() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/withParameters.kt"); + } + } } @TestMetadata("compiler/testData/codegen/box/callableReference/bound")