From d1c5a42124ac4b26d2b0370d95917a36ba2e7438 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Thu, 19 Mar 2020 14:03:01 +0300 Subject: [PATCH] KT-36024 Generate adapted callable references as lambdas Make sure both JVM and JVM_IR use the same information to determine whether a callable reference requires argument adaptation. --- .../kotlin/codegen/ClosureCodegen.java | 46 +++++++- .../kotlin/codegen/JvmRuntimeTypes.kt | 16 ++- .../binding/CodegenAnnotatingVisitor.java | 26 ++++- .../ir/FirBlackBoxCodegenTestGenerated.java | 5 + .../kotlin/fir/Fir2IrTextTestGenerated.java | 5 + .../calls/tower/ResolvedAtomCompleter.kt | 74 +++++++----- .../ReflectionReferencesGenerator.kt | 106 +++++++----------- .../components/CallableReferenceResolution.kt | 6 + ...oReflectionForAdaptedCallableReferences.kt | 38 +++++++ .../adaptedExtensionFunctions.txt | 9 +- .../adaptedWithCoercionToUnit.fir.txt | 41 +++++++ .../adaptedWithCoercionToUnit.kt | 11 ++ .../adaptedWithCoercionToUnit.txt | 62 ++++++++++ .../caoWithAdaptationForSam.txt | 6 +- .../constructorWithAdaptedArguments.txt | 24 ++-- .../callableReferences/kt37131.txt | 6 +- ...undMemberReferenceWithAdaptedArguments.txt | 9 +- .../withAdaptationForSam.txt | 3 +- .../withAdaptedArguments.fir.txt | 26 +++++ .../withAdaptedArguments.kt | 10 +- .../withAdaptedArguments.txt | 46 ++++++-- .../withArgumentAdaptationAndReceiver.txt | 45 ++++---- .../withVarargViewedAsArray.txt | 6 +- .../funInterface/samConversionInVarargs.txt | 3 +- .../samConversionOnCallableReference.txt | 12 +- .../codegen/BlackBoxCodegenTestGenerated.java | 5 + .../LightAnalysisModeTestGenerated.java | 5 + .../ir/IrBlackBoxCodegenTestGenerated.java | 5 + .../kotlin/ir/IrTextTestCaseGenerated.java | 5 + 29 files changed, 478 insertions(+), 183 deletions(-) create mode 100644 compiler/testData/codegen/box/callableReference/noReflectionForAdaptedCallableReferences.kt create mode 100644 compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.fir.txt create mode 100644 compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.kt create mode 100644 compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.txt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java index 263425d0c29..3545c526286 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java @@ -74,7 +74,9 @@ public class ClosureCodegen extends MemberCodegen { protected final Type asmType; protected final int visibilityFlag; private final boolean shouldHaveBoundReferenceReceiver; + private final boolean isRegularFunctionReference; private final boolean isOptimizedFunctionReference; + private final boolean isAdaptedFunctionReference; private Method constructor; protected Type superClassAsmType; @@ -125,9 +127,17 @@ public class ClosureCodegen extends MemberCodegen { assert closure != null : "Closure must be calculated for class: " + classDescriptor; this.shouldHaveBoundReferenceReceiver = CallableReferenceUtilKt.isForBoundCallableReference(closure); + + ClassifierDescriptor superClassDescriptor = superClassType.getConstructor().getDeclarationDescriptor(); + this.isRegularFunctionReference = + functionReferenceTarget != null && + superClassDescriptor == state.getJvmRuntimeTypes().getFunctionReference(); this.isOptimizedFunctionReference = functionReferenceTarget != null && - superClassType.getConstructor().getDeclarationDescriptor() == state.getJvmRuntimeTypes().getFunctionReferenceImpl(); + superClassDescriptor == state.getJvmRuntimeTypes().getFunctionReferenceImpl(); + this.isAdaptedFunctionReference = + functionReferenceTarget != null && + superClassDescriptor == state.getJvmRuntimeTypes().getLambda(); this.asmType = typeMapper.mapClass(classDescriptor); @@ -189,15 +199,29 @@ public class ClosureCodegen extends MemberCodegen { protected void generateClosureBody() { functionCodegen.generateMethod(JvmDeclarationOriginKt.OtherOrigin(element, funDescriptor), funDescriptor, strategy); - if (functionReferenceTarget != null && !isOptimizedFunctionReference) { + if (isRegularFunctionReference) { generateFunctionReferenceMethods(functionReferenceTarget); } + if (shouldHaveBoundReferenceReceiver && isAdaptedFunctionReference) { + generateBoundAdaptedCallableReferenceReceiverField(); + } + functionCodegen.generateDefaultIfNeeded( context.intoFunction(funDescriptor), funDescriptor, context.getContextKind(), DefaultParameterValueLoader.DEFAULT, null ); } + private void generateBoundAdaptedCallableReferenceReceiverField() { + v.newField( + JvmDeclarationOriginKt.OtherOrigin(element, funDescriptor), + ACC_PRIVATE, + BOUND_REFERENCE_RECEIVER, + OBJECT_TYPE.getDescriptor(), + null, null + ); + } + protected void generateBridges() { FunctionDescriptor erasedInterfaceFunction; if (samType == null) { @@ -500,11 +524,12 @@ public class ClosureCodegen extends MemberCodegen { List superCtorArgTypes = new ArrayList<>(); if (superClassAsmType.equals(LAMBDA) || superClassAsmType.equals(FUNCTION_REFERENCE) || superClassAsmType.equals(FUNCTION_REFERENCE_IMPL) || - CoroutineCodegenUtilKt.isCoroutineSuperClass(state.getLanguageVersionSettings(), superClassAsmType.getInternalName())) { + CoroutineCodegenUtilKt.isCoroutineSuperClass(state.getLanguageVersionSettings(), superClassAsmType.getInternalName()) + ) { int arity = calculateArity(); iv.iconst(arity); superCtorArgTypes.add(Type.INT_TYPE); - if (shouldHaveBoundReferenceReceiver) { + if (shouldHaveBoundReferenceReceiver && !isAdaptedFunctionReference) { CallableReferenceUtilKt.loadBoundReferenceReceiverParameter( iv, boundReceiverParameterIndex, boundReceiverType, boundReceiverKotlinType ); @@ -533,6 +558,19 @@ public class ClosureCodegen extends MemberCodegen { Type.getMethodDescriptor(Type.VOID_TYPE, superCtorArgTypes.toArray(new Type[0])), false ); + // Bound adapted function references store receiver in a separate field. + if (shouldHaveBoundReferenceReceiver && isAdaptedFunctionReference) { + iv.load(0, superClassAsmType); + CallableReferenceUtilKt.loadBoundReferenceReceiverParameter( + iv, boundReceiverParameterIndex, boundReceiverType, boundReceiverKotlinType + ); + iv.putfield( + asmType.getInternalName(), + BOUND_REFERENCE_RECEIVER, + OBJECT_TYPE.getDescriptor() + ); + } + iv.visitInsn(RETURN); FunctionCodegen.endVisit(iv, "constructor", element); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt index 9cb119d92e5..5971a712be9 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.kt @@ -43,9 +43,8 @@ class JvmRuntimeTypes( private fun propertyClasses(prefix: String, suffix: String): Lazy> = lazy { (0..2).map { i -> createClass(kotlinJvmInternalPackage, prefix + i + suffix) } } - private val lambda: ClassDescriptor by internal("Lambda") - - private val functionReference: ClassDescriptor by internal("FunctionReference") + val lambda: ClassDescriptor by internal("Lambda") + val functionReference: ClassDescriptor by internal("FunctionReference") val functionReferenceImpl: ClassDescriptor by internal("FunctionReferenceImpl") private val localVariableReference: ClassDescriptor by internal("LocalVariableReference") @@ -135,7 +134,8 @@ class JvmRuntimeTypes( fun getSupertypesForFunctionReference( referencedFunction: FunctionDescriptor, anonymousFunctionDescriptor: AnonymousFunctionDescriptor, - isBound: Boolean + isBound: Boolean, + isAdaptedCallableReference: Boolean ): Collection { val receivers = computeExpectedNumberOfReceivers(referencedFunction, isBound) @@ -151,7 +151,11 @@ class JvmRuntimeTypes( ) val suspendFunctionType = if (referencedFunction.isSuspend) suspendFunctionInterface?.defaultType else null - val superClass = if (generateOptimizedCallableReferenceSuperClasses) functionReferenceImpl else functionReference + val superClass = when { + isAdaptedCallableReference -> lambda + generateOptimizedCallableReferenceSuperClasses -> functionReferenceImpl + else -> functionReference + } return listOfNotNull(superClass.defaultType, functionType, suspendFunctionType) } @@ -172,4 +176,4 @@ class JvmRuntimeTypes( return classes[arity].defaultType } -} +} \ No newline at end of file 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 1c8a964ae51..282035414cf 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java @@ -16,6 +16,7 @@ import kotlin.collections.CollectionsKt; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.builtins.FunctionTypesKt; +import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.builtins.ReflectionTypes; import org.jetbrains.kotlin.cfg.WhenChecker; import org.jetbrains.kotlin.codegen.*; @@ -357,6 +358,28 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid { classStack.pop(); } + private boolean isAdaptedCallableReference( + @NotNull KtCallableReferenceExpression expression, + @NotNull ResolvedCall resolvedCall + ) { + CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor(); + if (!(resultingDescriptor instanceof FunctionDescriptor)) return false; + FunctionDescriptor functionDescriptor = (FunctionDescriptor) resultingDescriptor; + + // Callable reference is adapted if: + // - adapter arguments mapping is present in value arguments of corresponding resolved call; + // - return type is not Unit, and expected return type is Unit. + + if (!resolvedCall.getValueArguments().isEmpty()) return true; + + KotlinType callableReferenceType = bindingContext.getType(expression); + assert callableReferenceType != null : "No type for callable reference: " + expression.getText(); + KotlinType callableReferenceReturnType = CollectionsKt.last(callableReferenceType.getArguments()).getType(); + KotlinType functionReturnType = functionDescriptor.getReturnType(); + assert functionReturnType != null : "No return type for function: " + functionDescriptor; + return KotlinBuiltIns.isUnit(callableReferenceReturnType) && !KotlinBuiltIns.isUnit(functionReturnType); + } + @Override public void visitCallableReferenceExpression(@NotNull KtCallableReferenceExpression expression) { ResolvedCall referencedFunction = CallUtilKt.getResolvedCall(expression.getCallableReference(), bindingContext); @@ -380,7 +403,8 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid { if (callableDescriptor == null) return; supertypes = runtimeTypes.getSupertypesForFunctionReference( - (FunctionDescriptor) target, (AnonymousFunctionDescriptor) callableDescriptor, receiverType != null + (FunctionDescriptor) target, (AnonymousFunctionDescriptor) callableDescriptor, receiverType != null, + isAdaptedCallableReference(expression, referencedFunction) ); } 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 e6e40fbcaa3..e76516cb82b 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 @@ -1983,6 +1983,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/callableReference/nested.kt"); } + @TestMetadata("noReflectionForAdaptedCallableReferences.kt") + public void testNoReflectionForAdaptedCallableReferences() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/noReflectionForAdaptedCallableReferences.kt"); + } + @TestMetadata("optimizedSuperclasses_after.kt") public void testOptimizedSuperclasses_after() throws Exception { runTest("compiler/testData/codegen/box/callableReference/optimizedSuperclasses_after.kt"); 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 ecd4db91170..c8003444dce 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java @@ -1395,6 +1395,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/expressions/callableReferences/adaptedExtensionFunctions.kt"); } + @TestMetadata("adaptedWithCoercionToUnit.kt") + public void testAdaptedWithCoercionToUnit() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.kt"); + } + public void testAllFilesPresentInCallableReferences() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/irText/expressions/callableReferences"), Pattern.compile("^(.+)\\.kt$"), null, true); } 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 33c749c667d..484ca5189f8 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 @@ -7,10 +7,7 @@ package org.jetbrains.kotlin.resolve.calls.tower import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.createFunctionType -import org.jetbrains.kotlin.descriptors.CallableDescriptor -import org.jetbrains.kotlin.descriptors.FunctionDescriptor -import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.ReceiverParameterDescriptorImpl import org.jetbrains.kotlin.psi.KtElement @@ -41,6 +38,7 @@ 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.types.* +import org.jetbrains.kotlin.types.expressions.CoercionStrategy import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo @@ -396,7 +394,6 @@ class ResolvedAtomCompleter( callableReferenceAdaptation: CallableReferenceAdaptation? ) { if (callableReferenceAdaptation == null) return - val callElement = resolvedCall.call.callElement val isUnboundReference = resolvedCall.dispatchReceiver is TransientReceiver @@ -409,34 +406,55 @@ class ResolvedAtomCompleter( ) } + // We should record argument mapping only if callable reference requires adaptation: + // - argument mapping is non-trivial: any of the arguments were mapped as defaults or vararg elements; + // - result should be coerced. + var hasNonTrivialMapping = false + val mappedArguments = ArrayList>() for ((valueParameter, resolvedCallArgument) in callableReferenceAdaptation.mappedArguments) { - resolvedCall.recordValueArgument( - valueParameter, - when (resolvedCallArgument) { - ResolvedCallArgument.DefaultArgument -> - DefaultValueArgument.DEFAULT - is ResolvedCallArgument.SimpleArgument -> { - val valueArgument = makeFakeValueArgument(resolvedCallArgument.callArgument) - if (valueParameter.isVararg) - VarargValueArgument( - listOf( - FakeImplicitSpreadValueArgumentForCallableReferenceImpl(callElement, valueArgument) - ) - ) - else - ExpressionValueArgument(valueArgument) - } - is ResolvedCallArgument.VarargArgument -> - VarargValueArgument( - resolvedCallArgument.arguments.map { - makeFakeValueArgument(it) - } - ) + val resolvedValueArgument = when (resolvedCallArgument) { + ResolvedCallArgument.DefaultArgument -> { + hasNonTrivialMapping = true + DefaultValueArgument.DEFAULT } - ) + is ResolvedCallArgument.SimpleArgument -> { + val valueArgument = makeFakeValueArgument(resolvedCallArgument.callArgument) + if (valueParameter.isVararg) + VarargValueArgument( + listOf( + FakeImplicitSpreadValueArgumentForCallableReferenceImpl(callElement, valueArgument) + ) + ) + else + ExpressionValueArgument(valueArgument) + } + is ResolvedCallArgument.VarargArgument -> { + hasNonTrivialMapping = true + VarargValueArgument( + resolvedCallArgument.arguments.map { + makeFakeValueArgument(it) + } + ) + } + } + mappedArguments.add(valueParameter to resolvedValueArgument) + } + if (hasNonTrivialMapping || isCallableReferenceWithCoercion(resolvedCall, callableReferenceAdaptation.coercionStrategy)) { + for ((valueParameter, resolvedValueArgument) in mappedArguments) { + resolvedCall.recordValueArgument(valueParameter, resolvedValueArgument) + } } } + private fun isCallableReferenceWithCoercion( + resolvedCall: ResolvedCall, + coercionStrategy: CoercionStrategy + ): Boolean = + when (coercionStrategy) { + CoercionStrategy.NO_COERCION -> false + CoercionStrategy.COERCION_TO_UNIT -> !resolvedCall.resultingDescriptor.returnType!!.isUnit() + } + private fun completeCollectionLiteralCalls(collectionLiteralArgument: ResolvedCollectionLiteralAtom) { val psiCallArgument = collectionLiteralArgument.atom.psiCallArgument as CollectionLiteralKotlinCallArgumentImpl val context = psiCallArgument.outerCallContext 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 df37c85d9b9..1ac9f8fe58a 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 @@ -41,7 +41,7 @@ import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.expressions.DoubleColonLHS -import org.jetbrains.kotlin.utils.addIfNotNull +import org.jetbrains.kotlin.utils.SmartList class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : StatementGeneratorExtension(statementGenerator) { @@ -72,13 +72,10 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St val callBuilder = unwrapCallableDescriptorAndTypeArguments(resolvedCall, context.extensions.samConversion) - if (resolvedCall.valueArguments.isNotEmpty()) { - val adaptedCallableReference = generateAdaptedCallableReference(ktCallableReference, callBuilder) - if (adaptedCallableReference.hasResultAdaptation || - !isTrivialArgumentAdaptation(adaptedCallableReference.irAdapteeCall) - ) { - return adaptedCallableReference.irReferenceExpression - } + if (resolvedCall.valueArguments.isNotEmpty() || + requiresCoercionToUnit(resolvedDescriptor, getTypeInferredByFrontendOrFail(ktCallableReference)) + ) { + return generateAdaptedCallableReference(ktCallableReference, callBuilder) } return statementGenerator.generateCallReceiver( @@ -99,27 +96,15 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St } } - private fun isTrivialArgumentAdaptation(irAdapteeCall: IrFunctionAccessExpression): Boolean { - for (i in 0 until irAdapteeCall.valueArgumentsCount) { - val irValueArgument = irAdapteeCall.getValueArgument(i) ?: return false - if (irValueArgument is IrVararg) { - val irVarargElements = irValueArgument.elements - if (irVarargElements.size != 1 || irVarargElements[0] !is IrSpreadElement) return false - } - } - return true + private fun requiresCoercionToUnit(descriptor: CallableDescriptor, callableReferenceType: KotlinType): Boolean { + val ktExpectedReturnType = callableReferenceType.arguments.last().type + return KotlinBuiltIns.isUnit(ktExpectedReturnType) && !KotlinBuiltIns.isUnit(descriptor.returnType!!) } - private class AdaptedCallableReference( - val irReferenceExpression: IrExpression, - val irAdapteeCall: IrFunctionAccessExpression, - val hasResultAdaptation: Boolean - ) - private fun generateAdaptedCallableReference( ktCallableReference: KtCallableReferenceExpression, callBuilder: CallBuilder - ): AdaptedCallableReference { + ): IrExpressionBase { val adapteeDescriptor = callBuilder.descriptor if (adapteeDescriptor !is FunctionDescriptor) { throw AssertionError("Function descriptor expected in adapted callable reference: $adapteeDescriptor") @@ -140,10 +125,6 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St val irAdapterFun = createAdapterFun(startOffset, endOffset, adapteeDescriptor, ktExpectedParameterTypes, ktExpectedReturnType) val adapteeCall = createAdapteeCall(startOffset, endOffset, ktCallableReference, adapteeSymbol, callBuilder, irAdapterFun) val irCall = adapteeCall.callExpression - val irAdapteeCallInner = adapteeCall.innerCallExpression - - val tmpDispatchReceiver = adapteeCall.tmpDispatchReceiver - val tmpExtensionReceiver = adapteeCall.tmpExtensionReceiver irAdapterFun.body = IrBlockBodyImpl(startOffset, endOffset).apply { if (KotlinBuiltIns.isUnit(ktExpectedReturnType)) @@ -152,33 +133,27 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St statements.add(IrReturnImpl(startOffset, endOffset, context.irBuiltIns.nothingType, irAdapterFun.symbol, irCall)) } - val irBlock = IrBlockImpl(startOffset, endOffset, irFunctionalType).apply { - statements.addIfNotNull(tmpDispatchReceiver) - statements.addIfNotNull(tmpExtensionReceiver) - statements.add(irAdapterFun) - statements.add( - IrFunctionReferenceImpl( - startOffset, endOffset, - irFunctionalType, - irAdapterFun.symbol, - typeArgumentsCount = 0, - valueArgumentsCount = irAdapterFun.valueParameters.size, - reflectionTarget = null - ) + val irFunExpr = IrFunctionExpressionImpl( + startOffset, endOffset, + irFunctionalType, + irAdapterFun, + IrStatementOrigin.LAMBDA + ) + + return if (adapteeCall.tmpReceivers.isEmpty()) { + irFunExpr + } else { + IrBlockImpl( + startOffset, endOffset, irFunctionalType, + origin = null, + statements = adapteeCall.tmpReceivers + irFunExpr ) } - - return AdaptedCallableReference( - irBlock, irAdapteeCallInner, - KotlinBuiltIns.isUnit(ktExpectedReturnType) && !KotlinBuiltIns.isUnit(adapteeDescriptor.returnType!!) - ) } private class AdapteeCall( val callExpression: IrExpression, - val innerCallExpression: IrFunctionAccessExpression, - val tmpDispatchReceiver: IrVariable?, - val tmpExtensionReceiver: IrVariable? + val tmpReceivers: List ) private fun createAdapteeCall( @@ -192,9 +167,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St val resolvedCall = callBuilder.original val resolvedDescriptor = resolvedCall.resultingDescriptor - var irAdapteeCall: IrFunctionAccessExpression? = null - var tmpDispatchReceiver: IrVariable? = null - var tmpExtensionReceiver: IrVariable? = null + val tmpReceivers = SmartList() val irCall = statementGenerator.generateCallReceiver( ktCallableReference, @@ -228,7 +201,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St } else { val irVariable = statementGenerator.scope.createTemporaryVariable(irDispatchReceiver, "this") irAdapteeCallInner.dispatchReceiver = IrGetValueImpl(startOffset, endOffset, irVariable.symbol) - tmpDispatchReceiver = irVariable + tmpReceivers.add(irVariable) } } @@ -238,7 +211,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St } else { val irVariable = statementGenerator.scope.createTemporaryVariable(irExtensionReceiver, "receiver") irAdapteeCallInner.extensionReceiver = IrGetValueImpl(startOffset, endOffset, irVariable.symbol) - tmpExtensionReceiver = irVariable + tmpReceivers.add(irVariable) } } @@ -246,12 +219,10 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St putAdaptedValueArguments(startOffset, endOffset, irAdapteeCallInner, irAdapterFun, resolvedCall) - irAdapteeCall = irAdapteeCallInner - irAdapteeCallInner } - return AdapteeCall(irCall, irAdapteeCall!!, tmpDispatchReceiver, tmpExtensionReceiver) + return AdapteeCall(irCall, tmpReceivers) } private fun IrExpression.isSafeToUseWithoutCopying() = @@ -271,10 +242,6 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St resolvedCall: ResolvedCall<*> ) { val adaptedArguments = resolvedCall.valueArguments - if (adaptedArguments.isEmpty()) { - throw AssertionError("Callable reference with adapted arguments expected: ${resolvedCall.call.callElement.text}") - } - var shift = 0 if (resolvedCall.dispatchReceiver is TransientReceiver) { // Unbound callable reference 'A::foo', receiver is passed as a first parameter @@ -309,13 +276,16 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St is DefaultValueArgument -> null is VarargValueArgument -> - IrVarargImpl( - startOffset, endOffset, - valueParameter.type.toIrType(), valueParameter.varargElementType!!.toIrType(), - resolvedValueArgument.arguments.map { - adaptValueArgument(startOffset, endOffset, it, irAdapterFun, shift) - } - ) + if (resolvedValueArgument.arguments.isEmpty()) + null + else + IrVarargImpl( + startOffset, endOffset, + valueParameter.type.toIrType(), valueParameter.varargElementType!!.toIrType(), + resolvedValueArgument.arguments.map { + adaptValueArgument(startOffset, endOffset, it, irAdapterFun, shift) + } + ) is ExpressionValueArgument -> { val valueArgument = resolvedValueArgument.valueArgument!! diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt index c5ef19b3351..45a8709ed84 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt @@ -315,6 +315,12 @@ class CallableReferencesCandidateFactory( mappedArguments[valueParameter] = ResolvedCallArgument.VarargArgument(varargElements) } + for (valueParameter in descriptor.valueParameters) { + if (valueParameter.isVararg && valueParameter !in mappedArguments) { + mappedArguments[valueParameter] = ResolvedCallArgument.VarargArgument(emptyList()) + } + } + // lower(Unit!) = Unit val returnExpectedType = inputOutputTypes.outputType diff --git a/compiler/testData/codegen/box/callableReference/noReflectionForAdaptedCallableReferences.kt b/compiler/testData/codegen/box/callableReference/noReflectionForAdaptedCallableReferences.kt new file mode 100644 index 00000000000..14bd747a6bc --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/noReflectionForAdaptedCallableReferences.kt @@ -0,0 +1,38 @@ +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME +import kotlin.reflect.KCallable + +fun checkUnit(label: String, fn: () -> Unit) { + if (fn is KCallable<*>) { + throw AssertionError("$label is KCallable, ${fn::class.java.simpleName}") + } +} + +fun checkAny(label: String, fn: () -> Any) { + if (fn is KCallable<*>) { + throw AssertionError("$label is KCallable, ${fn::class.java.simpleName}") + } +} + +fun withDefaults(a: Int = 1, b: Int = 2) {} +fun withVarargs(vararg xs: Int) {} +fun withCoercion() = 1 + +class CWithDefaults(x: Int = 1, y: Int = 2) +class CWithVarargs(vararg xs: Int) + +fun box(): String { + checkUnit("::withDefaults", ::withDefaults) + checkUnit("::withVarargs", ::withVarargs) + checkUnit("::withCoercion", ::withCoercion) + + checkAny("::CWithDefaults", ::CWithDefaults) + checkAny("::CWithVarargs", ::CWithVarargs) + + // TODO KT-37604 + // checkUnit("::CWithDefaults", ::CWithDefaults) + // checkUnit("::CWithVarargs", ::CWithVarargs) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/expressions/callableReferences/adaptedExtensionFunctions.txt b/compiler/testData/ir/irText/expressions/callableReferences/adaptedExtensionFunctions.txt index 7b490a18b7e..b425769c771 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/adaptedExtensionFunctions.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/adaptedExtensionFunctions.txt @@ -44,7 +44,7 @@ FILE fqName: fileName:/adaptedExtensionFunctions.kt FUN name:testExtensionVararg visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public final fun use (f: @[ExtensionFunctionType] kotlin.Function2<.C, kotlin.Int, kotlin.Unit>): kotlin.Unit declared in ' type=kotlin.Unit origin=null - f: BLOCK type=kotlin.reflect.KFunction2<.C, kotlin.Int, kotlin.Unit> origin=null + f: FUN_EXPR type=kotlin.reflect.KFunction2<.C, kotlin.Int, kotlin.Unit> origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:extensionVararg visibility:local modality:FINAL <> (p0:.C, p1:kotlin.Int) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:.C VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p1 index:1 type:kotlin.Int @@ -52,11 +52,10 @@ FILE fqName: fileName:/adaptedExtensionFunctions.kt CALL 'public final fun extensionVararg (i: kotlin.Int, vararg s: kotlin.String): kotlin.Unit declared in ' type=kotlin.Unit origin=null $receiver: GET_VAR 'p0: .C declared in .testExtensionVararg.extensionVararg' type=.C origin=null i: GET_VAR 'p1: kotlin.Int declared in .testExtensionVararg.extensionVararg' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun extensionVararg (p0: .C, p1: kotlin.Int): kotlin.Unit declared in .testExtensionVararg' type=kotlin.reflect.KFunction2<.C, kotlin.Int, kotlin.Unit> origin=null reflectionTarget=null FUN name:testExtensionDefault visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public final fun use (f: @[ExtensionFunctionType] kotlin.Function2<.C, kotlin.Int, kotlin.Unit>): kotlin.Unit declared in ' type=kotlin.Unit origin=null - f: BLOCK type=kotlin.reflect.KFunction2<.C, kotlin.Int, kotlin.Unit> origin=null + f: FUN_EXPR type=kotlin.reflect.KFunction2<.C, kotlin.Int, kotlin.Unit> origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:extensionDefault visibility:local modality:FINAL <> (p0:.C, p1:kotlin.Int) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:.C VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p1 index:1 type:kotlin.Int @@ -64,11 +63,10 @@ FILE fqName: fileName:/adaptedExtensionFunctions.kt CALL 'public final fun extensionDefault (i: kotlin.Int, s: kotlin.String): kotlin.Unit declared in ' type=kotlin.Unit origin=null $receiver: GET_VAR 'p0: .C declared in .testExtensionDefault.extensionDefault' type=.C origin=null i: GET_VAR 'p1: kotlin.Int declared in .testExtensionDefault.extensionDefault' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun extensionDefault (p0: .C, p1: kotlin.Int): kotlin.Unit declared in .testExtensionDefault' type=kotlin.reflect.KFunction2<.C, kotlin.Int, kotlin.Unit> origin=null reflectionTarget=null FUN name:testExtensionBoth visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public final fun use (f: @[ExtensionFunctionType] kotlin.Function2<.C, kotlin.Int, kotlin.Unit>): kotlin.Unit declared in ' type=kotlin.Unit origin=null - f: BLOCK type=kotlin.reflect.KFunction2<.C, kotlin.Int, kotlin.Unit> origin=null + f: FUN_EXPR type=kotlin.reflect.KFunction2<.C, kotlin.Int, kotlin.Unit> origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:extensionBoth visibility:local modality:FINAL <> (p0:.C, p1:kotlin.Int) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:.C VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p1 index:1 type:kotlin.Int @@ -76,4 +74,3 @@ FILE fqName: fileName:/adaptedExtensionFunctions.kt CALL 'public final fun extensionBoth (i: kotlin.Int, s: kotlin.String, vararg t: kotlin.String): kotlin.Unit declared in ' type=kotlin.Unit origin=null $receiver: GET_VAR 'p0: .C declared in .testExtensionBoth.extensionBoth' type=.C origin=null i: GET_VAR 'p1: kotlin.Int declared in .testExtensionBoth.extensionBoth' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun extensionBoth (p0: .C, p1: kotlin.Int): kotlin.Unit declared in .testExtensionBoth' type=kotlin.reflect.KFunction2<.C, kotlin.Int, kotlin.Unit> origin=null reflectionTarget=null diff --git a/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.fir.txt new file mode 100644 index 00000000000..2d371f203fe --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.fir.txt @@ -0,0 +1,41 @@ +FILE fqName: fileName:/adaptedWithCoercionToUnit.kt + FUN name:useUnit0 visibility:public modality:FINAL <> (fn:kotlin.Function0) returnType:kotlin.Unit + VALUE_PARAMETER name:fn index:0 type:kotlin.Function0 + BLOCK_BODY + FUN name:useUnit1 visibility:public modality:FINAL <> (fn:kotlin.Function1) returnType:kotlin.Unit + VALUE_PARAMETER name:fn index:0 type:kotlin.Function1 + BLOCK_BODY + FUN name:fn0 visibility:public modality:FINAL <> () returnType:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun fn0 (): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=1 + FUN name:fn1 visibility:public modality:FINAL <> (x:kotlin.Int) returnType:kotlin.Int + VALUE_PARAMETER name:x index:0 type:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun fn1 (x: kotlin.Int): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=1 + FUN name:fnv visibility:public modality:FINAL <> (xs:kotlin.IntArray) returnType:kotlin.Int + VALUE_PARAMETER name:xs index:0 type:kotlin.IntArray varargElementType:kotlin.Int [vararg] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun fnv (vararg xs: kotlin.Int): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=1 + FUN name:test0 visibility:public modality:FINAL <> () returnType:IrErrorType + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test0 (): IrErrorType declared in ' + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun fn0 (): kotlin.Int declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= + FUN name:test1 visibility:public modality:FINAL <> () returnType:IrErrorType + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test1 (): IrErrorType declared in ' + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun fn1 (x: kotlin.Int): kotlin.Int declared in ' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= + FUN name:testV0 visibility:public modality:FINAL <> () returnType:IrErrorType + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testV0 (): IrErrorType declared in ' + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun fnv (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= + FUN name:testV1 visibility:public modality:FINAL <> () returnType:IrErrorType + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testV1 (): IrErrorType declared in ' + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun fnv (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= diff --git a/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.kt b/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.kt new file mode 100644 index 00000000000..cadfbe356dc --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.kt @@ -0,0 +1,11 @@ +fun useUnit0(fn: () -> Unit) {} +fun useUnit1(fn: (Int) -> Unit) {} + +fun fn0() = 1 +fun fn1(x: Int) = 1 +fun fnv(vararg xs: Int) = 1 + +fun test0() = useUnit0(::fn0) +fun test1() = useUnit1(::fn1) +fun testV0() = useUnit0(::fnv) +fun testV1() = useUnit1(::fnv) diff --git a/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.txt b/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.txt new file mode 100644 index 00000000000..1f3932a7050 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.txt @@ -0,0 +1,62 @@ +FILE fqName: fileName:/adaptedWithCoercionToUnit.kt + FUN name:useUnit0 visibility:public modality:FINAL <> (fn:kotlin.Function0) returnType:kotlin.Unit + VALUE_PARAMETER name:fn index:0 type:kotlin.Function0 + BLOCK_BODY + FUN name:useUnit1 visibility:public modality:FINAL <> (fn:kotlin.Function1) returnType:kotlin.Unit + VALUE_PARAMETER name:fn index:0 type:kotlin.Function1 + BLOCK_BODY + FUN name:fn0 visibility:public modality:FINAL <> () returnType:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun fn0 (): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=1 + FUN name:fn1 visibility:public modality:FINAL <> (x:kotlin.Int) returnType:kotlin.Int + VALUE_PARAMETER name:x index:0 type:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun fn1 (x: kotlin.Int): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=1 + FUN name:fnv visibility:public modality:FINAL <> (xs:kotlin.IntArray) returnType:kotlin.Int + VALUE_PARAMETER name:xs index:0 type:kotlin.IntArray varargElementType:kotlin.Int [vararg] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun fnv (vararg xs: kotlin.Int): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=1 + FUN name:test0 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test0 (): kotlin.Unit declared in ' + CALL 'public final fun useUnit0 (fn: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction0 origin=LAMBDA + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:fn0 visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun fn0 (): kotlin.Int declared in ' type=kotlin.Int origin=null + FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test1 (): kotlin.Unit declared in ' + CALL 'public final fun useUnit1 (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:fn1 visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun fn1 (x: kotlin.Int): kotlin.Int declared in ' type=kotlin.Int origin=null + x: GET_VAR 'p0: kotlin.Int declared in .test1.fn1' type=kotlin.Int origin=null + FUN name:testV0 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testV0 (): kotlin.Unit declared in ' + CALL 'public final fun useUnit0 (fn: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction0 origin=LAMBDA + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:fnv visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun fnv (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.Int origin=null + FUN name:testV1 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testV1 (): kotlin.Unit declared in ' + CALL 'public final fun useUnit1 (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:fnv visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun fnv (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.Int origin=null + xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int + GET_VAR 'p0: kotlin.Int declared in .testV1.fnv' type=kotlin.Int origin=null diff --git a/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.txt b/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.txt index d0a2f19daa2..b4cf1cfa444 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.txt @@ -109,7 +109,7 @@ FILE fqName: fileName:/caoWithAdaptationForSam.kt GET_OBJECT 'CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.A VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:.IFoo [val] TYPE_OP type=.IFoo origin=SAM_CONVERSION typeOperand=.IFoo - BLOCK type=kotlin.reflect.KFunction1 origin=null + FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:withVararg visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY @@ -117,7 +117,6 @@ FILE fqName: fileName:/caoWithAdaptationForSam.kt CALL 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.Int origin=null xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .test1.withVararg' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun withVararg (p0: kotlin.Int): kotlin.Unit declared in .test1' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null CALL 'public final fun set (i: .IFoo, newValue: kotlin.Int): kotlin.Unit [operator] declared in ' type=kotlin.Unit origin=PLUSEQ $receiver: GET_VAR 'val tmp_0: .A [val] declared in .test1' type=.A origin=null i: GET_VAR 'val tmp_1: .IFoo [val] declared in .test1' type=.IFoo origin=null @@ -133,7 +132,7 @@ FILE fqName: fileName:/caoWithAdaptationForSam.kt GET_OBJECT 'CLASS OBJECT name:B modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.B VAR IR_TEMPORARY_VARIABLE name:tmp_3 type:.IFoo2 [val] TYPE_OP type=.IFoo2 origin=SAM_CONVERSION typeOperand=.IFoo2 - BLOCK type=kotlin.reflect.KFunction1 origin=null + FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:withVararg visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY @@ -141,7 +140,6 @@ FILE fqName: fileName:/caoWithAdaptationForSam.kt CALL 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.Int origin=null xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .test2.withVararg' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun withVararg (p0: kotlin.Int): kotlin.Unit declared in .test2' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null CALL 'public final fun set (i: .IFoo2, newValue: kotlin.Int): kotlin.Unit [operator] declared in ' type=kotlin.Unit origin=PLUSEQ $receiver: GET_VAR 'val tmp_2: .B [val] declared in .test2' type=.B origin=null i: GET_VAR 'val tmp_3: .IFoo2 [val] declared in .test2' type=.IFoo2 origin=null diff --git a/compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.txt b/compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.txt index 3ff5c6353b4..7d600fb9771 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.txt @@ -70,7 +70,7 @@ FILE fqName: fileName:/constructorWithAdaptedArguments.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testConstructor (): kotlin.Any declared in ' CALL 'public final fun use (fn: kotlin.Function1): kotlin.Any declared in ' type=kotlin.Any origin=null - fn: BLOCK type=kotlin.reflect.KFunction1.C> origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction1.C> origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name: visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:.C VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY @@ -78,13 +78,12 @@ FILE fqName: fileName:/constructorWithAdaptedArguments.kt CONSTRUCTOR_CALL 'public constructor (vararg xs: kotlin.Int) [primary] declared in .C' type=.C origin=null xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .testConstructor.' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun (p0: kotlin.Int): .C declared in .testConstructor' type=kotlin.reflect.KFunction1.C> origin=null reflectionTarget=null FUN name:testInnerClassConstructor visibility:public modality:FINAL <> (outer:.Outer) returnType:kotlin.Any VALUE_PARAMETER name:outer index:0 type:.Outer BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInnerClassConstructor (outer: .Outer): kotlin.Any declared in ' CALL 'public final fun use (fn: kotlin.Function1): kotlin.Any declared in ' type=kotlin.Any origin=null - fn: BLOCK type=kotlin.reflect.KFunction1.Outer.Inner> origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction1.Outer.Inner> origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name: visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:.Outer.Inner VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY @@ -93,7 +92,6 @@ FILE fqName: fileName:/constructorWithAdaptedArguments.kt $outer: GET_VAR 'outer: .Outer declared in .testInnerClassConstructor' type=.Outer origin=null xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .testInnerClassConstructor.' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun (p0: kotlin.Int): .Outer.Inner declared in .testInnerClassConstructor' type=kotlin.reflect.KFunction1.Outer.Inner> origin=null reflectionTarget=null FUN name:testInnerClassConstructorCapturingOuter visibility:public modality:FINAL <> () returnType:kotlin.Any BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testInnerClassConstructorCapturingOuter (): kotlin.Any declared in ' @@ -101,12 +99,12 @@ FILE fqName: fileName:/constructorWithAdaptedArguments.kt fn: BLOCK type=kotlin.reflect.KFunction1.Outer.Inner> origin=null VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:.Outer [val] CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Outer' type=.Outer origin=null - FUN ADAPTER_FOR_CALLABLE_REFERENCE name: visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:.Outer.Inner - VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int - BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (p0: kotlin.Int): .Outer.Inner declared in .testInnerClassConstructorCapturingOuter' - CONSTRUCTOR_CALL 'public constructor (vararg xs: kotlin.Int) [primary] declared in .Outer.Inner' type=.Outer.Inner origin=null - $outer: GET_VAR 'val tmp_0: .Outer [val] declared in .testInnerClassConstructorCapturingOuter' type=.Outer origin=null - xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int - GET_VAR 'p0: kotlin.Int declared in .testInnerClassConstructorCapturingOuter.' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun (p0: kotlin.Int): .Outer.Inner declared in .testInnerClassConstructorCapturingOuter' type=kotlin.reflect.KFunction1.Outer.Inner> origin=null reflectionTarget=null + FUN_EXPR type=kotlin.reflect.KFunction1.Outer.Inner> origin=LAMBDA + FUN ADAPTER_FOR_CALLABLE_REFERENCE name: visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:.Outer.Inner + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (p0: kotlin.Int): .Outer.Inner declared in .testInnerClassConstructorCapturingOuter' + CONSTRUCTOR_CALL 'public constructor (vararg xs: kotlin.Int) [primary] declared in .Outer.Inner' type=.Outer.Inner origin=null + $outer: GET_VAR 'val tmp_0: .Outer [val] declared in .testInnerClassConstructorCapturingOuter' type=.Outer origin=null + xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int + GET_VAR 'p0: kotlin.Int declared in .testInnerClassConstructorCapturingOuter.' type=kotlin.Int origin=null diff --git a/compiler/testData/ir/irText/expressions/callableReferences/kt37131.txt b/compiler/testData/ir/irText/expressions/callableReferences/kt37131.txt index 29968c8c89d..98d8038792e 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/kt37131.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/kt37131.txt @@ -49,19 +49,17 @@ FILE fqName: fileName:/kt37131.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testFn (): kotlin.Any declared in ' CALL 'public final fun use (fn: kotlin.Function0): kotlin.Any declared in ' type=kotlin.Any origin=null - fn: BLOCK type=kotlin.reflect.KFunction0 origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction0 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo visibility:local modality:FINAL <> () returnType:kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='local final fun foo (): kotlin.String declared in .testFn' CALL 'public final fun foo (x: kotlin.String): kotlin.String declared in ' type=kotlin.String origin=null - FUNCTION_REFERENCE 'local final fun foo (): kotlin.String declared in .testFn' type=kotlin.reflect.KFunction0 origin=null reflectionTarget=null FUN name:testCtor visibility:public modality:FINAL <> () returnType:kotlin.Any BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testCtor (): kotlin.Any declared in ' CALL 'public final fun use (fn: kotlin.Function0): kotlin.Any declared in ' type=kotlin.Any origin=null - fn: BLOCK type=kotlin.reflect.KFunction0<.C> origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction0<.C> origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name: visibility:local modality:FINAL <> () returnType:.C BLOCK_BODY RETURN type=kotlin.Nothing from='local final fun (): .C declared in .testCtor' CONSTRUCTOR_CALL 'public constructor (x: kotlin.String) [primary] declared in .C' type=.C origin=null - FUNCTION_REFERENCE 'local final fun (): .C declared in .testCtor' type=kotlin.reflect.KFunction0<.C> origin=null reflectionTarget=null diff --git a/compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.txt b/compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.txt index 869ef7b8cc5..f2563dfc178 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.txt @@ -60,7 +60,7 @@ FILE fqName: fileName:/unboundMemberReferenceWithAdaptedArguments.kt FUN name:testUnbound visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public final fun use1 (fn: kotlin.Function2<.A, kotlin.Int, kotlin.Unit>): kotlin.Unit declared in ' type=kotlin.Unit origin=null - fn: BLOCK type=kotlin.reflect.KFunction2<.A, kotlin.Int, kotlin.Unit> origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction2<.A, kotlin.Int, kotlin.Unit> origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo visibility:local modality:FINAL <> (p0:.A, p1:kotlin.Int) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:.A VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p1 index:1 type:kotlin.Int @@ -70,12 +70,11 @@ FILE fqName: fileName:/unboundMemberReferenceWithAdaptedArguments.kt $this: GET_VAR 'p0: .A declared in .testUnbound.foo' type=.A origin=null xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p1: kotlin.Int declared in .testUnbound.foo' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun foo (p0: .A, p1: kotlin.Int): kotlin.Unit declared in .testUnbound' type=kotlin.reflect.KFunction2<.A, kotlin.Int, kotlin.Unit> origin=null reflectionTarget=null FUN name:testBound visibility:public modality:FINAL <> (a:.A) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:.A BLOCK_BODY CALL 'public final fun use2 (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null - fn: BLOCK type=kotlin.reflect.KFunction1 origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY @@ -84,11 +83,10 @@ FILE fqName: fileName:/unboundMemberReferenceWithAdaptedArguments.kt $this: GET_VAR 'a: .A declared in .testBound' type=.A origin=null xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .testBound.foo' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun foo (p0: kotlin.Int): kotlin.Unit declared in .testBound' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null FUN name:testObject visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public final fun use2 (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null - fn: BLOCK type=kotlin.reflect.KFunction1 origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY @@ -97,4 +95,3 @@ FILE fqName: fileName:/unboundMemberReferenceWithAdaptedArguments.kt $this: GET_OBJECT 'CLASS OBJECT name:Obj modality:FINAL visibility:public superTypes:[.A]' type=.Obj xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .testObject.foo' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun foo (p0: kotlin.Int): kotlin.Unit declared in .testObject' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.txt b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.txt index 448c0d617b2..04c9f496730 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.txt @@ -29,7 +29,7 @@ FILE fqName: fileName:/withAdaptationForSam.kt BLOCK_BODY CALL 'public final fun useFoo (foo: .IFoo): kotlin.Unit declared in ' type=kotlin.Unit origin=null foo: TYPE_OP type=.IFoo origin=SAM_CONVERSION typeOperand=.IFoo - BLOCK type=kotlin.reflect.KFunction1 origin=null + FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:withVararg visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY @@ -37,4 +37,3 @@ FILE fqName: fileName:/withAdaptationForSam.kt CALL 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.Int origin=null xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .test.withVararg' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun withVararg (p0: kotlin.Int): kotlin.Unit declared in .test' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.fir.txt index ed60bf5199d..f420b8df813 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.fir.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.fir.txt @@ -6,6 +6,12 @@ FILE fqName: fileName:/withAdaptedArguments.kt CALL 'public abstract fun invoke (p1: P1 of kotlin.Function1): R of kotlin.Function1 [operator] declared in kotlin.Function1' type=kotlin.String origin=INVOKE $this: GET_VAR 'fn: kotlin.Function1 declared in .use' type=kotlin.Function1 origin=null p1: CONST Int type=kotlin.Int value=1 + FUN name:use0 visibility:public modality:FINAL <> (fn:kotlin.Function0) returnType:kotlin.String + VALUE_PARAMETER name:fn index:0 type:kotlin.Function0 + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun use0 (fn: kotlin.Function0): kotlin.String declared in ' + CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=kotlin.String origin=INVOKE + $this: GET_VAR 'fn: kotlin.Function0 declared in .use0' type=kotlin.Function0 origin=null FUN name:coerceToUnit visibility:public modality:FINAL <> (fn:kotlin.Function1) returnType:kotlin.Unit VALUE_PARAMETER name:fn index:0 type:kotlin.Function1 BLOCK_BODY @@ -17,6 +23,16 @@ FILE fqName: fileName:/withAdaptedArguments.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun fnWithDefault (a: kotlin.Int, b: kotlin.Int): kotlin.String declared in ' CONST String type=kotlin.String value="abc" + FUN name:fnWithDefaults visibility:public modality:FINAL <> (a:kotlin.Int, b:kotlin.Int) returnType:kotlin.String + VALUE_PARAMETER name:a index:0 type:kotlin.Int + EXPRESSION_BODY + CONST Int type=kotlin.Int value=1 + VALUE_PARAMETER name:b index:1 type:kotlin.Int + EXPRESSION_BODY + CONST Int type=kotlin.Int value=2 + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun fnWithDefaults (a: kotlin.Int, b: kotlin.Int): kotlin.String declared in ' + CONST String type=kotlin.String value="" FUN name:fnWithVarargs visibility:public modality:FINAL <> (xs:kotlin.IntArray) returnType:kotlin.String VALUE_PARAMETER name:xs index:0 type:kotlin.IntArray varargElementType:kotlin.Int [vararg] BLOCK_BODY @@ -68,3 +84,13 @@ FILE fqName: fileName:/withAdaptedArguments.kt ERROR_CALL 'Unresolved reference: #' type=IrErrorType FUNCTION_REFERENCE 'public final fun importedObjectMemberWithVarargs (vararg xs: kotlin.Int): kotlin.String declared in .Host' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= $this: GET_OBJECT 'CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Host + FUN name:testDefault0 visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testDefault0 (): kotlin.String declared in ' + CALL 'public final fun use0 (fn: kotlin.Function0): kotlin.String declared in ' type=kotlin.String origin=null + fn: FUNCTION_REFERENCE 'public final fun fnWithDefaults (a: kotlin.Int, b: kotlin.Int): kotlin.String declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= + FUN name:testVararg0 visibility:public modality:FINAL <> () returnType:IrErrorType + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testVararg0 (): IrErrorType declared in ' + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun fnWithVarargs (vararg xs: kotlin.Int): kotlin.String declared in ' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.kt b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.kt index 853faa576ce..197261fc3a2 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.kt +++ b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.kt @@ -3,10 +3,14 @@ import Host.importedObjectMemberWithVarargs fun use(fn: (Int) -> String) = fn(1) +fun use0(fn: () -> String) = fn() + fun coerceToUnit(fn: (Int) -> Unit) {} fun fnWithDefault(a: Int, b: Int = 42) = "abc" +fun fnWithDefaults(a: Int = 1, b: Int = 2) = "" + fun fnWithVarargs(vararg xs: Int) = "abc" object Host { @@ -19,4 +23,8 @@ fun testVararg() = use(::fnWithVarargs) fun testCoercionToUnit() = coerceToUnit(::fnWithDefault) -fun testImportedObjectMember() = use(::importedObjectMemberWithVarargs) \ No newline at end of file +fun testImportedObjectMember() = use(::importedObjectMemberWithVarargs) + +fun testDefault0() = use0(::fnWithDefaults) + +fun testVararg0() = use0(::fnWithVarargs) \ No newline at end of file diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.txt b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.txt index c8361ace1a6..bbb46934ec3 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.txt @@ -6,6 +6,12 @@ FILE fqName: fileName:/withAdaptedArguments.kt CALL 'public abstract fun invoke (p1: P1 of kotlin.Function1): R of kotlin.Function1 [operator] declared in kotlin.Function1' type=kotlin.String origin=INVOKE $this: GET_VAR 'fn: kotlin.Function1 declared in .use' type=kotlin.Function1 origin=VARIABLE_AS_FUNCTION p1: CONST Int type=kotlin.Int value=1 + FUN name:use0 visibility:public modality:FINAL <> (fn:kotlin.Function0) returnType:kotlin.String + VALUE_PARAMETER name:fn index:0 type:kotlin.Function0 + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun use0 (fn: kotlin.Function0): kotlin.String declared in ' + CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=kotlin.String origin=INVOKE + $this: GET_VAR 'fn: kotlin.Function0 declared in .use0' type=kotlin.Function0 origin=VARIABLE_AS_FUNCTION FUN name:coerceToUnit visibility:public modality:FINAL <> (fn:kotlin.Function1) returnType:kotlin.Unit VALUE_PARAMETER name:fn index:0 type:kotlin.Function1 BLOCK_BODY @@ -17,6 +23,16 @@ FILE fqName: fileName:/withAdaptedArguments.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun fnWithDefault (a: kotlin.Int, b: kotlin.Int): kotlin.String declared in ' CONST String type=kotlin.String value="abc" + FUN name:fnWithDefaults visibility:public modality:FINAL <> (a:kotlin.Int, b:kotlin.Int) returnType:kotlin.String + VALUE_PARAMETER name:a index:0 type:kotlin.Int + EXPRESSION_BODY + CONST Int type=kotlin.Int value=1 + VALUE_PARAMETER name:b index:1 type:kotlin.Int + EXPRESSION_BODY + CONST Int type=kotlin.Int value=2 + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun fnWithDefaults (a: kotlin.Int, b: kotlin.Int): kotlin.String declared in ' + CONST String type=kotlin.String value="" FUN name:fnWithVarargs visibility:public modality:FINAL <> (xs:kotlin.IntArray) returnType:kotlin.String VALUE_PARAMETER name:xs index:0 type:kotlin.IntArray varargElementType:kotlin.Int [vararg] BLOCK_BODY @@ -51,19 +67,18 @@ FILE fqName: fileName:/withAdaptedArguments.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testDefault (): kotlin.String declared in ' CALL 'public final fun use (fn: kotlin.Function1): kotlin.String declared in ' type=kotlin.String origin=null - fn: BLOCK type=kotlin.reflect.KFunction1 origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:fnWithDefault visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.String VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY RETURN type=kotlin.Nothing from='local final fun fnWithDefault (p0: kotlin.Int): kotlin.String declared in .testDefault' CALL 'public final fun fnWithDefault (a: kotlin.Int, b: kotlin.Int): kotlin.String declared in ' type=kotlin.String origin=null a: GET_VAR 'p0: kotlin.Int declared in .testDefault.fnWithDefault' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun fnWithDefault (p0: kotlin.Int): kotlin.String declared in .testDefault' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null FUN name:testVararg visibility:public modality:FINAL <> () returnType:kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testVararg (): kotlin.String declared in ' CALL 'public final fun use (fn: kotlin.Function1): kotlin.String declared in ' type=kotlin.String origin=null - fn: BLOCK type=kotlin.reflect.KFunction1 origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:fnWithVarargs visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.String VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY @@ -71,24 +86,22 @@ FILE fqName: fileName:/withAdaptedArguments.kt CALL 'public final fun fnWithVarargs (vararg xs: kotlin.Int): kotlin.String declared in ' type=kotlin.String origin=null xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .testVararg.fnWithVarargs' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun fnWithVarargs (p0: kotlin.Int): kotlin.String declared in .testVararg' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null FUN name:testCoercionToUnit visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testCoercionToUnit (): kotlin.Unit declared in ' CALL 'public final fun coerceToUnit (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null - fn: BLOCK type=kotlin.reflect.KFunction1 origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:fnWithDefault visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public final fun fnWithDefault (a: kotlin.Int, b: kotlin.Int): kotlin.String declared in ' type=kotlin.String origin=null a: GET_VAR 'p0: kotlin.Int declared in .testCoercionToUnit.fnWithDefault' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun fnWithDefault (p0: kotlin.Int): kotlin.Unit declared in .testCoercionToUnit' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null FUN name:testImportedObjectMember visibility:public modality:FINAL <> () returnType:kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testImportedObjectMember (): kotlin.String declared in ' CALL 'public final fun use (fn: kotlin.Function1): kotlin.String declared in ' type=kotlin.String origin=null - fn: BLOCK type=kotlin.reflect.KFunction1 origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:importedObjectMemberWithVarargs visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.String VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY @@ -97,4 +110,21 @@ FILE fqName: fileName:/withAdaptedArguments.kt $this: GET_OBJECT 'CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Host xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .testImportedObjectMember.importedObjectMemberWithVarargs' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun importedObjectMemberWithVarargs (p0: kotlin.Int): kotlin.String declared in .testImportedObjectMember' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null + FUN name:testDefault0 visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testDefault0 (): kotlin.String declared in ' + CALL 'public final fun use0 (fn: kotlin.Function0): kotlin.String declared in ' type=kotlin.String origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction0 origin=LAMBDA + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:fnWithDefaults visibility:local modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun fnWithDefaults (): kotlin.String declared in .testDefault0' + CALL 'public final fun fnWithDefaults (a: kotlin.Int, b: kotlin.Int): kotlin.String declared in ' type=kotlin.String origin=null + FUN name:testVararg0 visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testVararg0 (): kotlin.String declared in ' + CALL 'public final fun use0 (fn: kotlin.Function0): kotlin.String declared in ' type=kotlin.String origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction0 origin=LAMBDA + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:fnWithVarargs visibility:local modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun fnWithVarargs (): kotlin.String declared in .testVararg0' + CALL 'public final fun fnWithVarargs (vararg xs: kotlin.Int): kotlin.String declared in ' type=kotlin.String origin=null diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withArgumentAdaptationAndReceiver.txt b/compiler/testData/ir/irText/expressions/callableReferences/withArgumentAdaptationAndReceiver.txt index 03641def909..a08f87a4728 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/withArgumentAdaptationAndReceiver.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/withArgumentAdaptationAndReceiver.txt @@ -21,7 +21,7 @@ FILE fqName: fileName:/withArgumentAdaptationAndReceiver.kt $this: VALUE_PARAMETER name: type:.Host BLOCK_BODY CALL 'public final fun use (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null - fn: BLOCK type=kotlin.reflect.KFunction1 origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:withVararg visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY @@ -30,14 +30,13 @@ FILE fqName: fileName:/withArgumentAdaptationAndReceiver.kt $this: GET_VAR ': .Host declared in .Host.testImplicitThis' type=.Host origin=null xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .Host.testImplicitThis.withVararg' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun withVararg (p0: kotlin.Int): kotlin.Unit declared in .Host.testImplicitThis' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null FUN name:testBoundReceiverLocalVal visibility:public modality:FINAL <> ($this:.Host) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.Host BLOCK_BODY VAR name:h type:.Host [val] CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Host' type=.Host origin=null CALL 'public final fun use (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null - fn: BLOCK type=kotlin.reflect.KFunction1 origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:withVararg visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY @@ -46,7 +45,6 @@ FILE fqName: fileName:/withArgumentAdaptationAndReceiver.kt $this: GET_VAR 'val h: .Host [val] declared in .Host.testBoundReceiverLocalVal' type=.Host origin=null xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .Host.testBoundReceiverLocalVal.withVararg' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun withVararg (p0: kotlin.Int): kotlin.Unit declared in .Host.testBoundReceiverLocalVal' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null FUN name:testBoundReceiverLocalVar visibility:public modality:FINAL <> ($this:.Host) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.Host BLOCK_BODY @@ -56,21 +54,21 @@ FILE fqName: fileName:/withArgumentAdaptationAndReceiver.kt fn: BLOCK type=kotlin.reflect.KFunction1 origin=null VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:.Host [val] GET_VAR 'var h: .Host [var] declared in .Host.testBoundReceiverLocalVar' type=.Host origin=null - FUN ADAPTER_FOR_CALLABLE_REFERENCE name:withVararg visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit - VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int - BLOCK_BODY - TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit - CALL 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.String declared in .Host' type=kotlin.String origin=null - $this: GET_VAR 'val tmp_0: .Host [val] declared in .Host.testBoundReceiverLocalVar' type=.Host origin=null - xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int - GET_VAR 'p0: kotlin.Int declared in .Host.testBoundReceiverLocalVar.withVararg' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun withVararg (p0: kotlin.Int): kotlin.Unit declared in .Host.testBoundReceiverLocalVar' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null + FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:withVararg visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.String declared in .Host' type=kotlin.String origin=null + $this: GET_VAR 'val tmp_0: .Host [val] declared in .Host.testBoundReceiverLocalVar' type=.Host origin=null + xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int + GET_VAR 'p0: kotlin.Int declared in .Host.testBoundReceiverLocalVar.withVararg' type=kotlin.Int origin=null FUN name:testBoundReceiverParameter visibility:public modality:FINAL <> ($this:.Host, h:.Host) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.Host VALUE_PARAMETER name:h index:0 type:.Host BLOCK_BODY CALL 'public final fun use (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null - fn: BLOCK type=kotlin.reflect.KFunction1 origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:withVararg visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY @@ -79,7 +77,6 @@ FILE fqName: fileName:/withArgumentAdaptationAndReceiver.kt $this: GET_VAR 'h: .Host declared in .Host.testBoundReceiverParameter' type=.Host origin=null xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .Host.testBoundReceiverParameter.withVararg' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun withVararg (p0: kotlin.Int): kotlin.Unit declared in .Host.testBoundReceiverParameter' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null FUN name:testBoundReceiverExpression visibility:public modality:FINAL <> ($this:.Host) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.Host BLOCK_BODY @@ -87,15 +84,15 @@ FILE fqName: fileName:/withArgumentAdaptationAndReceiver.kt fn: BLOCK type=kotlin.reflect.KFunction1 origin=null VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:.Host [val] CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Host' type=.Host origin=null - FUN ADAPTER_FOR_CALLABLE_REFERENCE name:withVararg visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit - VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int - BLOCK_BODY - TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit - CALL 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.String declared in .Host' type=kotlin.String origin=null - $this: GET_VAR 'val tmp_1: .Host [val] declared in .Host.testBoundReceiverExpression' type=.Host origin=null - xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int - GET_VAR 'p0: kotlin.Int declared in .Host.testBoundReceiverExpression.withVararg' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun withVararg (p0: kotlin.Int): kotlin.Unit declared in .Host.testBoundReceiverExpression' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null + FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:withVararg visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.String declared in .Host' type=kotlin.String origin=null + $this: GET_VAR 'val tmp_1: .Host [val] declared in .Host.testBoundReceiverExpression' type=.Host origin=null + xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int + GET_VAR 'p0: kotlin.Int declared in .Host.testBoundReceiverExpression.withVararg' type=kotlin.Int origin=null 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 diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withVarargViewedAsArray.txt b/compiler/testData/ir/irText/expressions/callableReferences/withVarargViewedAsArray.txt index 46e3e9e3c68..a371bb3d523 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/withVarargViewedAsArray.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/withVarargViewedAsArray.txt @@ -61,7 +61,7 @@ FILE fqName: fileName:/withVarargViewedAsArray.kt FUN name:testPlainArgs visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public final fun usePlainArgs (fn: kotlin.Function2): kotlin.Unit declared in ' type=kotlin.Unit origin=null - fn: BLOCK type=kotlin.reflect.KFunction2 origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction2 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:sum visibility:local modality:FINAL <> (p0:kotlin.Int, p1:kotlin.Int) returnType:kotlin.Int VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p1 index:1 type:kotlin.Int @@ -71,7 +71,6 @@ FILE fqName: fileName:/withVarargViewedAsArray.kt args: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .testPlainArgs.sum' type=kotlin.Int origin=null GET_VAR 'p1: kotlin.Int declared in .testPlainArgs.sum' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun sum (p0: kotlin.Int, p1: kotlin.Int): kotlin.Int declared in .testPlainArgs' type=kotlin.reflect.KFunction2 origin=null reflectionTarget=null FUN name:testPrimitiveArrayAsVararg visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public final fun usePrimitiveArray (fn: kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null @@ -83,7 +82,7 @@ FILE fqName: fileName:/withVarargViewedAsArray.kt FUN name:testArrayAndDefaults visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public final fun useStringArray (fn: kotlin.Function1, kotlin.Unit>): kotlin.Unit declared in ' type=kotlin.Unit origin=null - fn: BLOCK type=kotlin.reflect.KFunction1, kotlin.Unit> origin=null + fn: FUN_EXPR type=kotlin.reflect.KFunction1, kotlin.Unit> origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:zap visibility:local modality:FINAL <> (p0:kotlin.Array) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Array BLOCK_BODY @@ -91,4 +90,3 @@ FILE fqName: fileName:/withVarargViewedAsArray.kt b: VARARG type=kotlin.Array varargElementType=kotlin.String SPREAD_ELEMENT GET_VAR 'p0: kotlin.Array declared in .testArrayAndDefaults.zap' type=kotlin.Array origin=null - FUNCTION_REFERENCE 'local final fun zap (p0: kotlin.Array): kotlin.Unit declared in .testArrayAndDefaults' type=kotlin.reflect.KFunction1, kotlin.Unit> origin=null reflectionTarget=null diff --git a/compiler/testData/ir/irText/expressions/funInterface/samConversionInVarargs.txt b/compiler/testData/ir/irText/expressions/funInterface/samConversionInVarargs.txt index 93a65757fb9..b026dd34ed0 100644 --- a/compiler/testData/ir/irText/expressions/funInterface/samConversionInVarargs.txt +++ b/compiler/testData/ir/irText/expressions/funInterface/samConversionInVarargs.txt @@ -66,7 +66,7 @@ FILE fqName: fileName:/samConversionInVarargs.kt CALL 'public final fun useVararg (vararg foos: .IFoo): kotlin.Unit declared in ' type=kotlin.Unit origin=null foos: VARARG type=kotlin.Array.IFoo> varargElementType=.IFoo TYPE_OP type=.IFoo origin=SAM_CONVERSION typeOperand=.IFoo - BLOCK type=kotlin.reflect.KFunction1 origin=null + FUN_EXPR type=kotlin.reflect.KFunction1 origin=LAMBDA FUN ADAPTER_FOR_CALLABLE_REFERENCE name:withVarargOfInt visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int BLOCK_BODY @@ -74,4 +74,3 @@ FILE fqName: fileName:/samConversionInVarargs.kt CALL 'public final fun withVarargOfInt (vararg xs: kotlin.Int): kotlin.String declared in ' type=kotlin.String origin=null xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int GET_VAR 'p0: kotlin.Int declared in .testAdaptedCR.withVarargOfInt' type=kotlin.Int origin=null - FUNCTION_REFERENCE 'local final fun withVarargOfInt (p0: kotlin.Int): kotlin.Unit declared in .testAdaptedCR' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null diff --git a/compiler/testData/ir/irText/expressions/funInterface/samConversionOnCallableReference.txt b/compiler/testData/ir/irText/expressions/funInterface/samConversionOnCallableReference.txt index fdf8029e62b..78d535cc076 100644 --- a/compiler/testData/ir/irText/expressions/funInterface/samConversionOnCallableReference.txt +++ b/compiler/testData/ir/irText/expressions/funInterface/samConversionOnCallableReference.txt @@ -35,7 +35,11 @@ FILE fqName: fileName:/samConversionOnCallableReference.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testSamCosntructorOnAdapted (): .KRunnable declared in ' TYPE_OP type=.KRunnable origin=SAM_CONVERSION typeOperand=.KRunnable - FUNCTION_REFERENCE 'public final fun foo1 (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= + FUN_EXPR type=kotlin.reflect.KFunction0 origin=LAMBDA + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo1 visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun foo1 (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.Int origin=null FUN name:testSamConversion visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public final fun use (r: .KRunnable): kotlin.Unit declared in ' type=kotlin.Unit origin=null @@ -45,4 +49,8 @@ FILE fqName: fileName:/samConversionOnCallableReference.kt BLOCK_BODY CALL 'public final fun use (r: .KRunnable): kotlin.Unit declared in ' type=kotlin.Unit origin=null r: TYPE_OP type=.KRunnable origin=SAM_CONVERSION typeOperand=.KRunnable - FUNCTION_REFERENCE 'public final fun foo1 (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= + FUN_EXPR type=kotlin.reflect.KFunction0 origin=LAMBDA + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo1 visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun foo1 (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.Int origin=null diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 749d2a67424..e011f85cabf 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -2003,6 +2003,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/callableReference/nested.kt"); } + @TestMetadata("noReflectionForAdaptedCallableReferences.kt") + public void testNoReflectionForAdaptedCallableReferences() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/noReflectionForAdaptedCallableReferences.kt"); + } + @TestMetadata("optimizedSuperclasses_after.kt") public void testOptimizedSuperclasses_after() throws Exception { runTest("compiler/testData/codegen/box/callableReference/optimizedSuperclasses_after.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 60f7125a21a..a0dbbaa9d55 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -2003,6 +2003,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/callableReference/nested.kt"); } + @TestMetadata("noReflectionForAdaptedCallableReferences.kt") + public void testNoReflectionForAdaptedCallableReferences() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/noReflectionForAdaptedCallableReferences.kt"); + } + @TestMetadata("optimizedSuperclasses_after.kt") public void testOptimizedSuperclasses_after() throws Exception { runTest("compiler/testData/codegen/box/callableReference/optimizedSuperclasses_after.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 791281c110d..93253b1542d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -1983,6 +1983,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/callableReference/nested.kt"); } + @TestMetadata("noReflectionForAdaptedCallableReferences.kt") + public void testNoReflectionForAdaptedCallableReferences() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/noReflectionForAdaptedCallableReferences.kt"); + } + @TestMetadata("optimizedSuperclasses_after.kt") public void testOptimizedSuperclasses_after() throws Exception { runTest("compiler/testData/codegen/box/callableReference/optimizedSuperclasses_after.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index a828392d7d1..8796f093a1a 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1394,6 +1394,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/expressions/callableReferences/adaptedExtensionFunctions.kt"); } + @TestMetadata("adaptedWithCoercionToUnit.kt") + public void testAdaptedWithCoercionToUnit() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/adaptedWithCoercionToUnit.kt"); + } + public void testAllFilesPresentInCallableReferences() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/irText/expressions/callableReferences"), Pattern.compile("^(.+)\\.kt$"), null, true); }