diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt index 79542563f0a..d13b3b14322 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt @@ -7,10 +7,7 @@ package org.jetbrains.kotlin.fir.backend.generators import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.descriptors.Modality -import org.jetbrains.kotlin.fir.backend.Fir2IrComponents -import org.jetbrains.kotlin.fir.backend.Fir2IrConversionScope -import org.jetbrains.kotlin.fir.backend.FirMetadataSource -import org.jetbrains.kotlin.fir.backend.convertWithOffsets +import org.jetbrains.kotlin.fir.backend.* import org.jetbrains.kotlin.fir.declarations.FirFunction import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration import org.jetbrains.kotlin.fir.declarations.FirValueParameter @@ -21,23 +18,18 @@ import org.jetbrains.kotlin.fir.references.FirResolvedCallableReference import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.resolve.calls.FirFakeArgumentForCallableReference import org.jetbrains.kotlin.fir.resolve.calls.ResolvedCallArgument +import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.ir.builders.declarations.UNDEFINED_PARAMETER_INDEX import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.expressions.IrBlock -import org.jetbrains.kotlin.ir.expressions.IrExpression -import org.jetbrains.kotlin.ir.expressions.IrGetValue -import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin +import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl -import org.jetbrains.kotlin.ir.types.IrSimpleType -import org.jetbrains.kotlin.ir.types.IrType -import org.jetbrains.kotlin.ir.types.isUnit -import org.jetbrains.kotlin.ir.types.typeOrNull +import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.name.Name @@ -500,4 +492,101 @@ internal class AdapterGenerator( } return irCall } + + fun generateFunInterfaceConstructorReference( + callableReference: FirCallableReferenceAccess, + callableSymbol: FirFunctionSymbol<*>, + irReferenceType: IrType + ): IrExpression = + callableReference.convertWithOffsets { startOffset: Int, endOffset: Int -> + // { + // fun (function: ): = + // (function) + // :: + // } + + val irAdapterFun = generateFunInterfaceConstructorAdapter(startOffset, endOffset, callableSymbol, irReferenceType) + + val irAdapterRef = IrFunctionReferenceImpl( + startOffset, endOffset, + type = irReferenceType, + symbol = irAdapterFun.symbol, + typeArgumentsCount = irAdapterFun.typeParameters.size, + valueArgumentsCount = irAdapterFun.valueParameters.size, + reflectionTarget = irAdapterFun.symbol, + origin = IrStatementOrigin.FUN_INTERFACE_CONSTRUCTOR_REFERENCE + ) + + IrBlockImpl( + startOffset, endOffset, + irReferenceType, + IrStatementOrigin.FUN_INTERFACE_CONSTRUCTOR_REFERENCE, + listOf( + irAdapterFun, + irAdapterRef + ) + ) + } + + private fun IrSimpleType.getArgumentTypeAt(index: Int): IrType { + val irTypeArgument = this.arguments[index] as? IrTypeProjection + ?: throw AssertionError("Type projection expected at argument $index: ${this.render()}") + return irTypeArgument.type + } + + private fun generateFunInterfaceConstructorAdapter( + startOffset: Int, + endOffset: Int, + callableSymbol: FirFunctionSymbol<*>, + irReferenceType: IrType + ): IrSimpleFunction { + // Here irReferenceType is always kotlin.reflect.KFunction1 + val irSimpleReferenceType = irReferenceType as? IrSimpleType + ?: throw AssertionError("Class type expected: ${irReferenceType.render()}") + val irSamType = irSimpleReferenceType.getArgumentTypeAt(1) + val irFunctionType = irSimpleReferenceType.getArgumentTypeAt(0) + + val functionParameter = callableSymbol.valueParameterSymbols.singleOrNull() + ?: throw AssertionError("Single value parameter expected: ${callableSymbol.valueParameterSymbols}") + + return irFactory.createFunction( + startOffset, endOffset, + IrDeclarationOrigin.ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR, + IrSimpleFunctionSymbolImpl(), + callableSymbol.name, + DescriptorVisibilities.LOCAL, + Modality.FINAL, + irSamType, + isInline = false, + isExternal = false, + isTailrec = false, + isSuspend = true, + isOperator = false, + isInfix = false, + isExpect = false, + isFakeOverride = false + ).also { irAdapterFunction -> + symbolTable.enterScope(irAdapterFunction) + irAdapterFunction.dispatchReceiverParameter = null + irAdapterFunction.extensionReceiverParameter = null + val irFunctionParameter = createAdapterParameter( + irAdapterFunction, + functionParameter.name, + 0, + irFunctionType, + IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE + ) + irAdapterFunction.valueParameters = listOf(irFunctionParameter) + irAdapterFunction.body = irFactory.createExpressionBody( + startOffset, endOffset, + IrTypeOperatorCallImpl( + startOffset, endOffset, + irSamType, IrTypeOperator.SAM_CONVERSION, irSamType, + IrGetValueImpl(startOffset, endOffset, irFunctionParameter.symbol) + ) + ) + symbolTable.leaveScope(irAdapterFunction) + irAdapterFunction.parent = conversionScope.parent()!! + } + } } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt index 96873253979..093b9d5b8cc 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference import org.jetbrains.kotlin.fir.references.impl.FirReferencePlaceholderForResolvedAnnotations import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.resolve.FirSamResolverImpl +import org.jetbrains.kotlin.fir.resolve.calls.FirSyntheticFunctionSymbol import org.jetbrains.kotlin.fir.resolve.calls.getExpectedType import org.jetbrains.kotlin.fir.resolve.calls.isFunctional import org.jetbrains.kotlin.fir.resolve.fullyExpandedType @@ -43,6 +44,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl import org.jetbrains.kotlin.ir.types.* +import org.jetbrains.kotlin.ir.util.dump import org.jetbrains.kotlin.ir.util.isFunctionTypeOrSubtype import org.jetbrains.kotlin.ir.util.isInterface import org.jetbrains.kotlin.ir.util.render @@ -70,10 +72,22 @@ class CallAndReferenceGenerator( callableReferenceAccess: FirCallableReferenceAccess, explicitReceiverExpression: IrExpression? ): IrExpression { + val type = callableReferenceAccess.typeRef.toIrType() + val callableSymbol = callableReferenceAccess.calleeReference.toResolvedCallableSymbol() + if (callableSymbol?.origin == FirDeclarationOrigin.SamConstructor) { + assert(explicitReceiverExpression == null) { + "Fun interface constructor reference should be unbound: ${explicitReceiverExpression?.dump()}" + } + return adapterGenerator.generateFunInterfaceConstructorReference( + callableReferenceAccess, + callableSymbol as FirSyntheticFunctionSymbol, + type + ) + } + val symbol = callableReferenceAccess.calleeReference.toSymbolForCall( callableReferenceAccess.dispatchReceiver, session, classifierStorage, declarationStorage, conversionScope ) - val type = callableReferenceAccess.typeRef.toIrType() // val x by y -> // val `x$delegate` = y // val x get() = `x$delegate`.getValue(this, ::x) diff --git a/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.fir.ir.txt b/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.fir.ir.txt index d97d7d81950..02f7a46d0a8 100644 --- a/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.fir.ir.txt @@ -59,32 +59,70 @@ FILE fqName: fileName:/funInterfaceConstructorReference.kt FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.reflect.KFunction1, .KRunnable> BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test1 (): kotlin.reflect.KFunction1, .KRunnable> declared in ' - FUNCTION_REFERENCE 'public final fun KRunnable (function: kotlin.Function0): .KRunnable declared in ' type=kotlin.reflect.KFunction1, .KRunnable> origin=null reflectionTarget= + BLOCK type=kotlin.reflect.KFunction1, .KRunnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE + FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:KRunnable visibility:local modality:FINAL <> (function:kotlin.Function0) returnType:.KRunnable [suspend] + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function0 + EXPRESSION_BODY + TYPE_OP type=.KRunnable origin=SAM_CONVERSION typeOperand=.KRunnable + GET_VAR 'function: kotlin.Function0 declared in .test1.KRunnable' type=kotlin.Function0 origin=null + FUNCTION_REFERENCE 'local final fun KRunnable (function: kotlin.Function0): .KRunnable [suspend] declared in .test1' type=kotlin.reflect.KFunction1, .KRunnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget= FUN name:test1a visibility:public modality:FINAL <> () returnType:kotlin.reflect.KFunction1, .KRunnable> BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test1a (): kotlin.reflect.KFunction1, .KRunnable> declared in ' - FUNCTION_REFERENCE 'public final fun KRunnable (function: kotlin.Function0): .KRunnable declared in ' type=kotlin.reflect.KFunction1, .KRunnable> origin=null reflectionTarget= - FUN name:test1b visibility:public modality:FINAL <> () returnType:kotlin.reflect.KFunction + BLOCK type=kotlin.reflect.KFunction1, .KRunnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE + FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:KRunnable visibility:local modality:FINAL <> (function:kotlin.Function0) returnType:.KRunnable [suspend] + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function0 + EXPRESSION_BODY + TYPE_OP type=.KRunnable origin=SAM_CONVERSION typeOperand=.KRunnable + GET_VAR 'function: kotlin.Function0 declared in .test1a.KRunnable' type=kotlin.Function0 origin=null + FUNCTION_REFERENCE 'local final fun KRunnable (function: kotlin.Function0): .KRunnable [suspend] declared in .test1a' type=kotlin.reflect.KFunction1, .KRunnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget= + FUN name:test1b visibility:public modality:FINAL <> () returnType:kotlin.reflect.KFunction<.KRunnable> BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test1b (): kotlin.reflect.KFunction declared in ' - FUNCTION_REFERENCE 'public final fun Runnable (function: kotlin.Function0): java.lang.Runnable declared in java.lang' type=kotlin.reflect.KFunction1, java.lang.Runnable> origin=null reflectionTarget= + RETURN type=kotlin.Nothing from='public final fun test1b (): kotlin.reflect.KFunction<.KRunnable> declared in ' + BLOCK type=kotlin.reflect.KFunction1, .KRunnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE + FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:KRunnable visibility:local modality:FINAL <> (function:kotlin.Function0) returnType:.KRunnable [suspend] + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function0 + EXPRESSION_BODY + TYPE_OP type=.KRunnable origin=SAM_CONVERSION typeOperand=.KRunnable + GET_VAR 'function: kotlin.Function0 declared in .test1b.KRunnable' type=kotlin.Function0 origin=null + FUNCTION_REFERENCE 'local final fun KRunnable (function: kotlin.Function0): .KRunnable [suspend] declared in .test1b' type=kotlin.reflect.KFunction1, .KRunnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget= FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Function1, .KSupplier> BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test2 (): kotlin.Function1, .KSupplier> declared in ' - FUNCTION_REFERENCE 'public final fun KSupplier (function: kotlin.Function0.KSupplier>): .KSupplier.KSupplier> declared in ' type=kotlin.reflect.KFunction1, .KSupplier> origin=null reflectionTarget= - : kotlin.String + BLOCK type=kotlin.reflect.KFunction1, .KSupplier> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE + FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:KSupplier visibility:local modality:FINAL <> (function:kotlin.Function0) returnType:.KSupplier [suspend] + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function0 + EXPRESSION_BODY + TYPE_OP type=.KSupplier origin=SAM_CONVERSION typeOperand=.KSupplier + GET_VAR 'function: kotlin.Function0 declared in .test2.KSupplier' type=kotlin.Function0 origin=null + FUNCTION_REFERENCE 'local final fun KSupplier (function: kotlin.Function0): .KSupplier [suspend] declared in .test2' type=kotlin.reflect.KFunction1, .KSupplier> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget= FUN name:test2a visibility:public modality:FINAL <> () returnType:kotlin.Function1, .KSupplier> BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test2a (): kotlin.Function1, .KSupplier> declared in ' - FUNCTION_REFERENCE 'public final fun KSupplier (function: kotlin.Function0.KSupplier>): .KSupplier.KSupplier> declared in ' type=kotlin.reflect.KFunction1, .KSupplier> origin=null reflectionTarget= - : kotlin.String + BLOCK type=kotlin.reflect.KFunction1, .KSupplier> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE + FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:KSupplier visibility:local modality:FINAL <> (function:kotlin.Function0) returnType:.KSupplier [suspend] + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function0 + EXPRESSION_BODY + TYPE_OP type=.KSupplier origin=SAM_CONVERSION typeOperand=.KSupplier + GET_VAR 'function: kotlin.Function0 declared in .test2a.KSupplier' type=kotlin.Function0 origin=null + FUNCTION_REFERENCE 'local final fun KSupplier (function: kotlin.Function0): .KSupplier [suspend] declared in .test2a' type=kotlin.reflect.KFunction1, .KSupplier> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget= FUN name:test3 visibility:public modality:FINAL <> () returnType:kotlin.Function1, .KConsumer> BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test3 (): kotlin.Function1, .KConsumer> declared in ' - FUNCTION_REFERENCE 'public final fun KConsumer (function: kotlin.Function1.KConsumer, kotlin.Unit>): .KConsumer.KConsumer> declared in ' type=kotlin.reflect.KFunction1, .KConsumer> origin=null reflectionTarget= - : kotlin.String + BLOCK type=kotlin.reflect.KFunction1, .KConsumer> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE + FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:KConsumer visibility:local modality:FINAL <> (function:kotlin.Function1) returnType:.KConsumer [suspend] + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function1 + EXPRESSION_BODY + TYPE_OP type=.KConsumer origin=SAM_CONVERSION typeOperand=.KConsumer + GET_VAR 'function: kotlin.Function1 declared in .test3.KConsumer' type=kotlin.Function1 origin=null + FUNCTION_REFERENCE 'local final fun KConsumer (function: kotlin.Function1): .KConsumer [suspend] declared in .test3' type=kotlin.reflect.KFunction1, .KConsumer> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget= FUN name:test3a visibility:public modality:FINAL <> () returnType:kotlin.Function1, .KConsumer> BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test3a (): kotlin.Function1, .KConsumer> declared in ' - FUNCTION_REFERENCE 'public final fun KConsumer (function: kotlin.Function1.KConsumer, kotlin.Unit>): .KConsumer.KConsumer> declared in ' type=kotlin.reflect.KFunction1, .KConsumer> origin=null reflectionTarget= - : kotlin.String + BLOCK type=kotlin.reflect.KFunction1, .KConsumer> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE + FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:KConsumer visibility:local modality:FINAL <> (function:kotlin.Function1) returnType:.KConsumer [suspend] + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function1 + EXPRESSION_BODY + TYPE_OP type=.KConsumer origin=SAM_CONVERSION typeOperand=.KConsumer + GET_VAR 'function: kotlin.Function1 declared in .test3a.KConsumer' type=kotlin.Function1 origin=null + FUNCTION_REFERENCE 'local final fun KConsumer (function: kotlin.Function1): .KConsumer [suspend] declared in .test3a' type=kotlin.reflect.KFunction1, .KConsumer> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget= diff --git a/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.fir.kt.txt b/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.fir.kt.txt index a252547c84f..ea7d030a284 100644 --- a/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.fir.kt.txt @@ -17,29 +17,58 @@ fun interface KConsumer { } fun test1(): KFunction1, KRunnable> { - return ::KRunnable + return { // BLOCK + local suspend fun KRunnable(function: Function0): KRunnable function /*-> KRunnable */ + + ::KRunnable + } } fun test1a(): KFunction1, KRunnable> { - return ::KRunnable + return { // BLOCK + local suspend fun KRunnable(function: Function0): KRunnable function /*-> KRunnable */ + + ::KRunnable + } } -fun test1b(): KFunction { - return ::Runnable +fun test1b(): KFunction { + return { // BLOCK + local suspend fun KRunnable(function: Function0): KRunnable function /*-> KRunnable */ + + ::KRunnable + } } fun test2(): Function1, KSupplier> { - return ::KSupplier/*()*/ + return { // BLOCK + local suspend fun KSupplier(function: Function0): KSupplier function /*-> KSupplier */ + + ::KSupplier + } } fun test2a(): Function1, KSupplier> { - return ::KSupplier/*()*/ + return { // BLOCK + local suspend fun KSupplier(function: Function0): KSupplier function /*-> KSupplier */ + + ::KSupplier + } } fun test3(): Function1, KConsumer> { - return ::KConsumer/*()*/ + return { // BLOCK + local suspend fun KConsumer(function: Function1): KConsumer function /*-> KConsumer */ + + ::KConsumer + } } fun test3a(): Function1, KConsumer> { - return ::KConsumer/*()*/ + return { // BLOCK + local suspend fun KConsumer(function: Function1): KConsumer function /*-> KConsumer */ + + ::KConsumer + } } + diff --git a/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.ir.txt b/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.ir.txt index 854135f8234..7469def4e87 100644 --- a/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.ir.txt +++ b/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.ir.txt @@ -76,16 +76,16 @@ FILE fqName: fileName:/funInterfaceConstructorReference.kt TYPE_OP type=.KRunnable origin=SAM_CONVERSION typeOperand=.KRunnable GET_VAR 'function: kotlin.Function0 declared in .test1a.KRunnable' type=kotlin.Function0 origin=null FUNCTION_REFERENCE 'local final fun KRunnable (function: kotlin.Function0): .KRunnable declared in .test1a' type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0, .KRunnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget= - FUN name:test1b visibility:public modality:FINAL <> () returnType:kotlin.reflect.KFunction + FUN name:test1b visibility:public modality:FINAL <> () returnType:kotlin.reflect.KFunction<.KRunnable> BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test1b (): kotlin.reflect.KFunction declared in ' - BLOCK type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0, java.lang.Runnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE - FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:Runnable visibility:local modality:FINAL <> (function:kotlin.Function0) returnType:java.lang.Runnable + RETURN type=kotlin.Nothing from='public final fun test1b (): kotlin.reflect.KFunction<.KRunnable> declared in ' + BLOCK type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0, .KRunnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE + FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:KRunnable visibility:local modality:FINAL <> (function:kotlin.Function0) returnType:.KRunnable VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function0 EXPRESSION_BODY - TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable - GET_VAR 'function: kotlin.Function0 declared in .test1b.Runnable' type=kotlin.Function0 origin=null - FUNCTION_REFERENCE 'local final fun Runnable (function: kotlin.Function0): java.lang.Runnable declared in .test1b' type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0, java.lang.Runnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget= + TYPE_OP type=.KRunnable origin=SAM_CONVERSION typeOperand=.KRunnable + GET_VAR 'function: kotlin.Function0 declared in .test1b.KRunnable' type=kotlin.Function0 origin=null + FUNCTION_REFERENCE 'local final fun KRunnable (function: kotlin.Function0): .KRunnable declared in .test1b' type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0, .KRunnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget= FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Function1, .KSupplier> BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test2 (): kotlin.Function1, .KSupplier> declared in ' diff --git a/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.kt b/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.kt index 476dbf728a5..cf8957dc747 100644 --- a/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.kt +++ b/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.kt @@ -24,7 +24,7 @@ fun test1() = ::KRunnable fun test1a() = ::KR -fun test1b(): KFunction = ::Runnable +fun test1b(): KFunction = ::KRunnable fun test2(): (() -> String) -> KSupplier = ::KSupplier diff --git a/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.kt.txt b/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.kt.txt index c41934bd1ba..4736efbba56 100644 --- a/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.kt.txt +++ b/compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.kt.txt @@ -32,11 +32,11 @@ fun test1a(): KFunction1<@ParameterName(name = "function") Function0, KRun } } -fun test1b(): KFunction { +fun test1b(): KFunction { return { // BLOCK - local fun Runnable(function: Function0): Runnable function /*-> Runnable */ + local fun KRunnable(function: Function0): KRunnable function /*-> KRunnable */ - ::Runnable + ::KRunnable } }