diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java index 1d9ff0887f1..3600998a642 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java @@ -1444,6 +1444,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/expressions/callableReferences/kt37131.kt"); } + @TestMetadata("suspendConversion.kt") + public void testSuspendConversion() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.kt"); + } + @TestMetadata("typeArguments.kt") public void testTypeArguments() throws Exception { runTest("compiler/testData/ir/irText/expressions/callableReferences/typeArguments.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt index 484ca5189f8..98196ae9703 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceAdaptation +import org.jetbrains.kotlin.resolve.calls.components.SuspendConversionStrategy import org.jetbrains.kotlin.resolve.calls.components.isVararg import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext import org.jetbrains.kotlin.resolve.calls.context.ContextDependency @@ -35,8 +36,8 @@ import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategyImpl import org.jetbrains.kotlin.resolve.calls.util.CallMaker import org.jetbrains.kotlin.resolve.checkers.MissingDependencySupertypeChecker import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver -import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue +import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.expressions.CoercionStrategy import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver @@ -439,21 +440,28 @@ class ResolvedAtomCompleter( } mappedArguments.add(valueParameter to resolvedValueArgument) } - if (hasNonTrivialMapping || isCallableReferenceWithCoercion(resolvedCall, callableReferenceAdaptation.coercionStrategy)) { + if (hasNonTrivialMapping || isCallableReferenceWithImplicitConversion(resolvedCall, callableReferenceAdaptation)) { for ((valueParameter, resolvedValueArgument) in mappedArguments) { resolvedCall.recordValueArgument(valueParameter, resolvedValueArgument) } } } - private fun isCallableReferenceWithCoercion( + private fun isCallableReferenceWithImplicitConversion( resolvedCall: ResolvedCall, - coercionStrategy: CoercionStrategy - ): Boolean = - when (coercionStrategy) { - CoercionStrategy.NO_COERCION -> false - CoercionStrategy.COERCION_TO_UNIT -> !resolvedCall.resultingDescriptor.returnType!!.isUnit() - } + callableReferenceAdaptation: CallableReferenceAdaptation + ): Boolean { + val resultingDescriptor = resolvedCall.resultingDescriptor + + // TODO drop return type check - see noCoercionToUnitIfFunctionAlreadyReturnsUnit.kt + if (callableReferenceAdaptation.coercionStrategy == CoercionStrategy.COERCION_TO_UNIT && !resultingDescriptor.returnType!!.isUnit()) + return true + + if (callableReferenceAdaptation.suspendConversionStrategy == SuspendConversionStrategy.SUSPEND_CONVERSION) + return true + + return false + } private fun completeCollectionLiteralCalls(collectionLiteralArgument: ResolvedCollectionLiteralAtom) { val psiCallArgument = collectionLiteralArgument.atom.psiCallArgument as CollectionLiteralKotlinCallArgumentImpl diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index 7b728f2c440..3fc3c6ef42c 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -689,7 +689,8 @@ class ExpressionCodegen( override fun visitElement(element: IrElement, data: BlockInfo) = throw AssertionError( "Unexpected IR element found during code generation. Either code generation for it " + - "is not implemented, or it should have been lowered: ${element.render()}" + "is not implemented, or it should have been lowered:\n" + + element.render() ) override fun visitClass(declaration: IrClass, data: BlockInfo): PromisedValue { diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt index 28381f9040f..a92e9c1cdba 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt @@ -77,10 +77,12 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St val callBuilder = unwrapCallableDescriptorAndTypeArguments(resolvedCall, context.extensions.samConversion) + val callableReferenceType = getTypeInferredByFrontendOrFail(ktCallableReference) if (resolvedCall.valueArguments.isNotEmpty() || - requiresCoercionToUnit(resolvedDescriptor, getTypeInferredByFrontendOrFail(ktCallableReference)) + requiresCoercionToUnit(resolvedDescriptor, callableReferenceType) || + requiresSuspendConversion(resolvedDescriptor, callableReferenceType) ) { - return generateAdaptedCallableReference(ktCallableReference, callBuilder) + return generateAdaptedCallableReference(ktCallableReference, callBuilder, callableReferenceType) } return statementGenerator.generateCallReceiver( @@ -91,7 +93,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St ).call { dispatchReceiverValue, extensionReceiverValue -> generateCallableReference( ktCallableReference, - getTypeInferredByFrontendOrFail(ktCallableReference), + callableReferenceType, callBuilder.descriptor, callBuilder.typeArguments ).also { irCallableReference -> @@ -106,9 +108,15 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St return KotlinBuiltIns.isUnit(ktExpectedReturnType) && !KotlinBuiltIns.isUnit(descriptor.returnType!!) } + private fun requiresSuspendConversion(descriptor: CallableDescriptor, callableReferenceType: KotlinType): Boolean = + descriptor is FunctionDescriptor && + !descriptor.isSuspend && + callableReferenceType.isKSuspendFunctionType + private fun generateAdaptedCallableReference( ktCallableReference: KtCallableReferenceExpression, - callBuilder: CallBuilder + callBuilder: CallBuilder, + callableReferenceType: KotlinType ): IrExpression { val adapteeDescriptor = callBuilder.descriptor if (adapteeDescriptor !is FunctionDescriptor) { @@ -128,7 +136,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St val ktExpectedParameterTypes = ktFunctionalTypeArguments.take(ktFunctionalTypeArguments.size - 1).map { it.type } val irAdapterFun = - createAdapterFun(startOffset, endOffset, adapteeDescriptor, ktExpectedParameterTypes, ktExpectedReturnType, callBuilder) + createAdapterFun(startOffset, endOffset, adapteeDescriptor, ktExpectedParameterTypes, ktExpectedReturnType, callBuilder, callableReferenceType) val irCall = createAdapteeCall(startOffset, endOffset, adapteeSymbol, callBuilder, irAdapterFun) irAdapterFun.body = IrBlockBodyImpl(startOffset, endOffset).apply { @@ -326,9 +334,13 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St ktExpectedParameterTypes: List, ktExpectedReturnType: KotlinType, callBuilder: CallBuilder, + callableReferenceType: KotlinType ): IrSimpleFunction { val adapterFunctionDescriptor = WrappedSimpleFunctionDescriptor() + val hasSuspendConversion = !adapteeDescriptor.isSuspend && + callableReferenceType.isKSuspendFunctionType + return context.symbolTable.declareSimpleFunction( startOffset, endOffset, IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE, @@ -345,7 +357,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St isInline = adapteeDescriptor.isInline, // TODO ? isExternal = false, isTailrec = false, - isSuspend = adapteeDescriptor.isSuspend, // TODO ? + isSuspend = adapteeDescriptor.isSuspend || hasSuspendConversion, isOperator = adapteeDescriptor.isOperator, // TODO ? isExpect = false, isFakeOverride = false diff --git a/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.fir.txt new file mode 100644 index 00000000000..ebeea134d75 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.fir.txt @@ -0,0 +1,88 @@ +FILE fqName: fileName:/suspendConversion.kt + FUN name:useSuspend visibility:public modality:FINAL <> (fn:kotlin.coroutines.SuspendFunction0) returnType:kotlin.Unit + VALUE_PARAMETER name:fn index:0 type:kotlin.coroutines.SuspendFunction0 + BLOCK_BODY + FUN name:useSuspendInt visibility:public modality:FINAL <> (fn:kotlin.coroutines.SuspendFunction1) returnType:kotlin.Unit + VALUE_PARAMETER name:fn index:0 type:kotlin.coroutines.SuspendFunction1 + BLOCK_BODY + FUN name:foo0 visibility:public modality:FINAL <> () returnType:kotlin.Unit [suspend] + BLOCK_BODY + FUN name:foo1 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + FUN name:fooInt visibility:public modality:FINAL <> (x:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER name:x index:0 type:kotlin.Int + BLOCK_BODY + FUN name:foo2 visibility:public modality:FINAL <> (xs:kotlin.IntArray) returnType:kotlin.Unit + VALUE_PARAMETER name:xs index:0 type:kotlin.IntArray varargElementType:kotlin.Int [vararg] + BLOCK_BODY + FUN name:foo3 visibility:public modality:FINAL <> () returnType:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun foo3 (): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=42 + FUN name:foo4 visibility:public modality:FINAL <> (i:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER name:i index:0 type:kotlin.Int + EXPRESSION_BODY + CONST Int type=kotlin.Int value=42 + BLOCK_BODY + CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C + CONSTRUCTOR visibility:public <> () returnType:.C [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:bar visibility:public modality:FINAL <> ($this:.C) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.C + BLOCK_BODY + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:testLambda visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useSuspend (fn: kotlin.coroutines.SuspendFunction0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUN_EXPR type=kotlin.coroutines.SuspendFunction0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit [suspend] + BLOCK_BODY + CALL 'public final fun foo1 (): kotlin.Unit declared in ' type=kotlin.Unit origin=null + FUN name:testNoCoversion visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useSuspend (fn: kotlin.coroutines.SuspendFunction0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public final fun foo0 (): kotlin.Unit [suspend] declared in ' type=kotlin.reflect.KSuspendFunction0 origin=null reflectionTarget= + FUN name:testSuspendPlain visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun foo1 (): kotlin.Unit declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= + FUN name:testSuspendWithArgs visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun fooInt (x: kotlin.Int): kotlin.Unit declared in ' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= + FUN name:testWithVararg visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun foo2 (vararg xs: kotlin.Int): kotlin.Unit declared in ' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= + FUN name:testWithVarargMapped visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun foo2 (vararg xs: kotlin.Int): kotlin.Unit declared in ' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= + FUN name:testWithCoercionToUnit visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun foo3 (): kotlin.Int declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= + FUN name:testWithDefaults visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun foo4 (i: kotlin.Int): kotlin.Unit declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= + FUN name:testWithBoundReceiver visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun bar (): kotlin.Unit declared in .C' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= + $this: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .C' type=.C origin=null diff --git a/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.kt b/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.kt new file mode 100644 index 00000000000..9ae40e03e79 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.kt @@ -0,0 +1,33 @@ +// !LANGUAGE: +SuspendConversion + +fun useSuspend(fn: suspend () -> Unit) {} +fun useSuspendInt(fn: suspend (Int) -> Unit) {} + +suspend fun foo0() {} +fun foo1() {} +fun fooInt(x: Int) {} +fun foo2(vararg xs: Int) {} +fun foo3(): Int = 42 +fun foo4(i: Int = 42) {} + +class C { + fun bar() {} +} + +fun testLambda() { useSuspend { foo1() } } + +fun testNoCoversion() { useSuspend(::foo0) } + +fun testSuspendPlain() { useSuspend(::foo1) } + +fun testSuspendWithArgs() { useSuspendInt(::fooInt) } + +fun testWithVararg() { useSuspend(::foo2) } + +fun testWithVarargMapped() { useSuspendInt(::foo2) } + +fun testWithCoercionToUnit() { useSuspend(::foo3) } + +fun testWithDefaults() { useSuspend(::foo4) } + +fun testWithBoundReceiver() { useSuspend(C()::bar) } \ No newline at end of file diff --git a/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.txt b/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.txt new file mode 100644 index 00000000000..0659949b44f --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.txt @@ -0,0 +1,120 @@ +FILE fqName: fileName:/suspendConversion.kt + FUN name:useSuspend visibility:public modality:FINAL <> (fn:kotlin.coroutines.SuspendFunction0) returnType:kotlin.Unit + VALUE_PARAMETER name:fn index:0 type:kotlin.coroutines.SuspendFunction0 + BLOCK_BODY + FUN name:useSuspendInt visibility:public modality:FINAL <> (fn:kotlin.coroutines.SuspendFunction1) returnType:kotlin.Unit + VALUE_PARAMETER name:fn index:0 type:kotlin.coroutines.SuspendFunction1 + BLOCK_BODY + FUN name:foo0 visibility:public modality:FINAL <> () returnType:kotlin.Unit [suspend] + BLOCK_BODY + FUN name:foo1 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + FUN name:fooInt visibility:public modality:FINAL <> (x:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER name:x index:0 type:kotlin.Int + BLOCK_BODY + FUN name:foo2 visibility:public modality:FINAL <> (xs:kotlin.IntArray) returnType:kotlin.Unit + VALUE_PARAMETER name:xs index:0 type:kotlin.IntArray varargElementType:kotlin.Int [vararg] + BLOCK_BODY + FUN name:foo3 visibility:public modality:FINAL <> () returnType:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun foo3 (): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=42 + FUN name:foo4 visibility:public modality:FINAL <> (i:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER name:i index:0 type:kotlin.Int + EXPRESSION_BODY + CONST Int type=kotlin.Int value=42 + BLOCK_BODY + CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C + CONSTRUCTOR visibility:public <> () returnType:.C [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:bar visibility:public modality:FINAL <> ($this:.C) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.C + BLOCK_BODY + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:testLambda visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useSuspend (fn: kotlin.coroutines.SuspendFunction0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUN_EXPR type=kotlin.coroutines.SuspendFunction0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit [suspend] + BLOCK_BODY + CALL 'public final fun foo1 (): kotlin.Unit declared in ' type=kotlin.Unit origin=null + FUN name:testNoCoversion visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useSuspend (fn: kotlin.coroutines.SuspendFunction0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public final fun foo0 (): kotlin.Unit [suspend] declared in ' type=kotlin.reflect.KSuspendFunction0 origin=null reflectionTarget= + FUN name:testSuspendPlain visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useSuspend (fn: kotlin.coroutines.SuspendFunction0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUN_EXPR type=kotlin.coroutines.SuspendFunction0 origin=ADAPTED_FUNCTION_REFERENCE + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo1 visibility:local modality:FINAL <> () returnType:kotlin.Unit [suspend] + BLOCK_BODY + CALL 'public final fun foo1 (): kotlin.Unit declared in ' type=kotlin.Unit origin=null + FUN name:testSuspendWithArgs visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useSuspendInt (fn: kotlin.coroutines.SuspendFunction1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUN_EXPR type=kotlin.coroutines.SuspendFunction1 origin=ADAPTED_FUNCTION_REFERENCE + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:fooInt visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit [suspend] + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int + BLOCK_BODY + CALL 'public final fun fooInt (x: kotlin.Int): kotlin.Unit declared in ' type=kotlin.Unit origin=null + x: GET_VAR 'p0: kotlin.Int declared in .testSuspendWithArgs.fooInt' type=kotlin.Int origin=null + FUN name:testWithVararg visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useSuspend (fn: kotlin.coroutines.SuspendFunction0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUN_EXPR type=kotlin.coroutines.SuspendFunction0 origin=ADAPTED_FUNCTION_REFERENCE + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo2 visibility:local modality:FINAL <> () returnType:kotlin.Unit [suspend] + BLOCK_BODY + CALL 'public final fun foo2 (vararg xs: kotlin.Int): kotlin.Unit declared in ' type=kotlin.Unit origin=null + FUN name:testWithVarargMapped visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useSuspendInt (fn: kotlin.coroutines.SuspendFunction1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUN_EXPR type=kotlin.coroutines.SuspendFunction1 origin=ADAPTED_FUNCTION_REFERENCE + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo2 visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit [suspend] + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int + BLOCK_BODY + CALL 'public final fun foo2 (vararg xs: kotlin.Int): kotlin.Unit declared in ' type=kotlin.Unit origin=null + xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int + GET_VAR 'p0: kotlin.Int declared in .testWithVarargMapped.foo2' type=kotlin.Int origin=null + FUN name:testWithCoercionToUnit visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useSuspend (fn: kotlin.coroutines.SuspendFunction0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUN_EXPR type=kotlin.coroutines.SuspendFunction0 origin=ADAPTED_FUNCTION_REFERENCE + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo3 visibility:local modality:FINAL <> () returnType:kotlin.Unit [suspend] + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun foo3 (): kotlin.Int declared in ' type=kotlin.Int origin=null + FUN name:testWithDefaults visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useSuspend (fn: kotlin.coroutines.SuspendFunction0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUN_EXPR type=kotlin.coroutines.SuspendFunction0 origin=ADAPTED_FUNCTION_REFERENCE + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo4 visibility:local modality:FINAL <> () returnType:kotlin.Unit [suspend] + BLOCK_BODY + CALL 'public final fun foo4 (i: kotlin.Int): kotlin.Unit declared in ' type=kotlin.Unit origin=null + FUN name:testWithBoundReceiver visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useSuspend (fn: kotlin.coroutines.SuspendFunction0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: BLOCK type=kotlin.coroutines.SuspendFunction0 origin=ADAPTED_FUNCTION_REFERENCE + VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:.C [val] + CONSTRUCTOR_CALL 'public constructor () [primary] declared in .C' type=.C origin=null + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:bar visibility:local modality:FINAL <> ($receiver:.C) returnType:kotlin.Unit [suspend] + $receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:receiver type:.C + BLOCK_BODY + CALL 'public final fun bar (): kotlin.Unit declared in .C' type=kotlin.Unit origin=null + $this: GET_VAR 'receiver: .C declared in .testWithBoundReceiver.bar' type=.C origin=ADAPTED_FUNCTION_REFERENCE + FUNCTION_REFERENCE 'local final fun bar (): kotlin.Unit [suspend] declared in .testWithBoundReceiver' type=kotlin.coroutines.SuspendFunction0 origin=ADAPTED_FUNCTION_REFERENCE reflectionTarget=null + $receiver: GET_VAR 'val tmp_0: .C [val] declared in .testWithBoundReceiver' type=.C origin=null diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index a03db31f24c..0618cbe9124 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1443,6 +1443,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/expressions/callableReferences/kt37131.kt"); } + @TestMetadata("suspendConversion.kt") + public void testSuspendConversion() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/suspendConversion.kt"); + } + @TestMetadata("typeArguments.kt") public void testTypeArguments() throws Exception { runTest("compiler/testData/ir/irText/expressions/callableReferences/typeArguments.kt");