PSI2IR KT-47939 callable references to fun interface constructors

This commit is contained in:
Dmitry Petrov
2021-11-29 17:01:28 +03:00
committed by TeamCityServer
parent 1fd0dec5e7
commit 27a144f86f
9 changed files with 376 additions and 23 deletions
@@ -1394,6 +1394,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
runTest("compiler/testData/ir/irText/expressions/funImportedFromObject.kt");
}
@Test
@TestMetadata("funInterfaceConstructorReference.kt")
public void testFunInterfaceConstructorReference() throws Exception {
runTest("compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.kt");
}
@Test
@TestMetadata("genericConstructorCallWithTypeArguments.kt")
public void testGenericConstructorCallWithTypeArguments() throws Exception {
@@ -18,8 +18,12 @@ package org.jetbrains.kotlin.psi2ir.generators
import org.jetbrains.kotlin.builtins.*
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.synthetic.FunctionInterfaceConstructorDescriptor
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.DescriptorMetadataSource
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.descriptors.IrBuiltInsOverDescriptors
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.*
@@ -67,32 +71,122 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
fun generateCallableReference(ktCallableReference: KtCallableReferenceExpression): IrExpression {
val resolvedCall = getResolvedCall(ktCallableReference.callableReference)!!
val resolvedDescriptor = resolvedCall.resultingDescriptor
val callableReferenceType = getTypeInferredByFrontendOrFail(ktCallableReference)
val callBuilder = unwrapCallableDescriptorAndTypeArguments(resolvedCall)
val callableReferenceType = getTypeInferredByFrontendOrFail(ktCallableReference)
if (resolvedCall.valueArguments.isNotEmpty() ||
return when {
resolvedDescriptor is FunctionInterfaceConstructorDescriptor ||
resolvedDescriptor.original is FunctionInterfaceConstructorDescriptor ->
generateFunctionInterfaceConstructorReference(
ktCallableReference, callableReferenceType, callBuilder.descriptor
)
isAdaptedCallableReference(resolvedCall, resolvedDescriptor, callableReferenceType) ->
generateAdaptedCallableReference(ktCallableReference, callBuilder, callableReferenceType)
else ->
statementGenerator.generateCallReceiver(
ktCallableReference,
resolvedDescriptor,
resolvedCall.dispatchReceiver, resolvedCall.extensionReceiver,resolvedCall.contextReceivers,
isSafe = false
).call { dispatchReceiverValue, extensionReceiverValue, _ ->
generateCallableReference(
ktCallableReference,
callableReferenceType,
callBuilder.descriptor,
callBuilder.typeArguments
).also { irCallableReference ->
irCallableReference.dispatchReceiver = dispatchReceiverValue?.loadIfExists()
irCallableReference.extensionReceiver = extensionReceiverValue?.loadIfExists()
}
}
}
}
private fun isAdaptedCallableReference(
resolvedCall: ResolvedCall<out CallableDescriptor>,
resolvedDescriptor: CallableDescriptor,
callableReferenceType: KotlinType
) = resolvedCall.valueArguments.isNotEmpty() ||
requiresCoercionToUnit(resolvedDescriptor, callableReferenceType) ||
requiresSuspendConversion(resolvedDescriptor, callableReferenceType)
) {
return generateAdaptedCallableReference(ktCallableReference, callBuilder, callableReferenceType)
}
return statementGenerator.generateCallReceiver(
ktCallableReference,
resolvedDescriptor, resolvedCall.dispatchReceiver,
resolvedCall.extensionReceiver,
resolvedCall.contextReceivers,
isSafe = false
).call { dispatchReceiverValue, extensionReceiverValue, _ ->
generateCallableReference(
ktCallableReference,
callableReferenceType,
callBuilder.descriptor,
callBuilder.typeArguments
).also { irCallableReference ->
irCallableReference.dispatchReceiver = dispatchReceiverValue?.loadIfExists()
irCallableReference.extensionReceiver = extensionReceiverValue?.loadIfExists()
private fun generateFunctionInterfaceConstructorReference(
ktCallableReference: KtCallableReferenceExpression,
callableReferenceType: KotlinType,
descriptor: CallableDescriptor
): IrExpression {
// {
// fun <ADAPTER_FUN>(function: <FUN_TYPE>): <FUN_INTERFACE_TYPE> =
// <FUN_INTERFACE_TYPE>(function)
// ::<ADAPTER_FUN>
// }
val startOffset = ktCallableReference.startOffsetSkippingComments
val endOffset = ktCallableReference.endOffset
val irReferenceType = callableReferenceType.toIrType()
val irAdapterFun = createFunInterfaceConstructorAdapter(startOffset, endOffset, descriptor)
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
)
return IrBlockImpl(
startOffset, endOffset,
irReferenceType,
IrStatementOrigin.FUN_INTERFACE_CONSTRUCTOR_REFERENCE,
listOf(
irAdapterFun,
irAdapterRef
)
)
}
private fun createFunInterfaceConstructorAdapter(startOffset: Int, endOffset: Int, descriptor: CallableDescriptor): IrSimpleFunction {
val samType = descriptor.returnType
?: throw AssertionError("Unresolved return type: $descriptor")
val samClassDescriptor = samType.constructor.declarationDescriptor as? ClassDescriptor
?: throw AssertionError("Class type expected: $samType")
val irSamType = samType.toIrType()
val functionParameter = descriptor.valueParameters.singleOrNull()
?: throw AssertionError("Single value parameter expected: $descriptor")
return context.irFactory.createFunction(
startOffset, endOffset,
IrDeclarationOrigin.ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR,
IrSimpleFunctionSymbolImpl(),
name = samClassDescriptor.name,
visibility = DescriptorVisibilities.LOCAL,
modality = Modality.FINAL,
returnType = irSamType,
isInline = false, isExternal = false, isTailrec = false, isSuspend = false, isOperator = false, isInfix = false,
isExpect = false, isFakeOverride = false
).also { irAdapterFun ->
context.symbolTable.withScope(irAdapterFun) {
// TODO irAdapterFun.metadata = ...?
irAdapterFun.dispatchReceiverParameter = null
irAdapterFun.extensionReceiverParameter = null
val irFnParameter = createAdapterParameter(startOffset, endOffset, functionParameter.name, 0, functionParameter.type)
irAdapterFun.valueParameters = listOf(irFnParameter)
irAdapterFun.body =
context.irFactory.createExpressionBody(
startOffset, endOffset,
IrTypeOperatorCallImpl(
startOffset, endOffset,
irSamType, IrTypeOperator.SAM_CONVERSION, irSamType,
IrGetValueImpl(startOffset, endOffset, irFnParameter.symbol)
)
)
}
}
}
@@ -16,6 +16,8 @@
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.ir.expressions.IrStatementOriginImpl
interface IrDeclarationOrigin {
object DEFINED : IrDeclarationOriginImpl("DEFINED")
object FAKE_OVERRIDE : IrDeclarationOriginImpl("FAKE_OVERRIDE")
@@ -75,6 +77,7 @@ interface IrDeclarationOrigin {
object ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE : IrDeclarationOriginImpl("ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE")
object ADAPTER_FOR_SUSPEND_CONVERSION : IrDeclarationOriginImpl("ADAPTER_FOR_SUSPEND_CONVERSION", isSynthetic = true)
object ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION : IrDeclarationOriginImpl("ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION")
object ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR : IrDeclarationOriginImpl("ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR", isSynthetic = true)
object GENERATED_SAM_IMPLEMENTATION : IrDeclarationOriginImpl("GENERATED_SAM_IMPLEMENTATION")
object SYNTHETIC_GENERATED_SAM_IMPLEMENTATION : IrDeclarationOriginImpl("SYNTHETIC_GENERATED_SAM_IMPLEMENTATION", isSynthetic = true)
@@ -90,7 +90,8 @@ interface IrStatementOrigin {
object ANONYMOUS_FUNCTION : IrStatementOriginImpl("ANONYMOUS_FUNCTION")
object OBJECT_LITERAL : IrStatementOriginImpl("OBJECT_LITERAL")
object ADAPTED_FUNCTION_REFERENCE : IrStatementOriginImpl("ADAPTED_FUNCTION_REFERENCE")
object SUSPEND_CONVERSION: IrStatementOriginImpl("SUSPEND_CONVERSION")
object SUSPEND_CONVERSION : IrStatementOriginImpl("SUSPEND_CONVERSION")
object FUN_INTERFACE_CONSTRUCTOR_REFERENCE : IrStatementOriginImpl("FUN_INTERFACE_CONSTRUCTOR_REFERENCE")
object INITIALIZE_PROPERTY_FROM_PARAMETER : IrStatementOriginImpl("INITIALIZE_PROPERTY_FROM_PARAMETER")
object INITIALIZE_FIELD : IrStatementOriginImpl("INITIALIZE_FIELD")
@@ -0,0 +1,128 @@
FILE fqName:<root> fileName:/funInterfaceConstructorReference.kt
CLASS INTERFACE name:KRunnable modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.KRunnable
FUN name:run visibility:public modality:ABSTRACT <> ($this:<root>.KRunnable) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.KRunnable
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
TYPEALIAS name:KR visibility:public expandedType:<root>.KRunnable
CLASS INTERFACE name:KSupplier modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.KSupplier<T of <root>.KSupplier>
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
FUN name:get visibility:public modality:ABSTRACT <> ($this:<root>.KSupplier<T of <root>.KSupplier>) returnType:T of <root>.KSupplier
$this: VALUE_PARAMETER name:<this> type:<root>.KSupplier<T of <root>.KSupplier>
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
TYPEALIAS name:KSS visibility:public expandedType:<root>.KSupplier<kotlin.String>
CLASS INTERFACE name:KConsumer modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.KConsumer<T of <root>.KConsumer>
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
FUN name:accept visibility:public modality:ABSTRACT <> ($this:<root>.KConsumer<T of <root>.KConsumer>, x:T of <root>.KConsumer) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.KConsumer<T of <root>.KConsumer>
VALUE_PARAMETER name:x index:0 type:T of <root>.KConsumer
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
TYPEALIAS name:KCS visibility:public expandedType:<root>.KConsumer<kotlin.String>
FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0<kotlin.Unit>, <root>.KRunnable>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test1 (): kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0<kotlin.Unit>, <root>.KRunnable> declared in <root>'
BLOCK type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0<kotlin.Unit>, <root>.KRunnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE
FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:KRunnable visibility:local modality:FINAL <> (function:kotlin.Function0<kotlin.Unit>) returnType:<root>.KRunnable
VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function0<kotlin.Unit>
EXPRESSION_BODY
TYPE_OP type=<root>.KRunnable origin=SAM_CONVERSION typeOperand=<root>.KRunnable
GET_VAR 'function: kotlin.Function0<kotlin.Unit> declared in <root>.test1.KRunnable' type=kotlin.Function0<kotlin.Unit> origin=null
FUNCTION_REFERENCE 'local final fun KRunnable (function: kotlin.Function0<kotlin.Unit>): <root>.KRunnable declared in <root>.test1' type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0<kotlin.Unit>, <root>.KRunnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget=<same>
FUN name:test1a visibility:public modality:FINAL <> () returnType:kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0<kotlin.Unit>, <root>.KRunnable>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test1a (): kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0<kotlin.Unit>, <root>.KRunnable> declared in <root>'
BLOCK type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0<kotlin.Unit>, <root>.KRunnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE
FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:KRunnable visibility:local modality:FINAL <> (function:kotlin.Function0<kotlin.Unit>) returnType:<root>.KRunnable
VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function0<kotlin.Unit>
EXPRESSION_BODY
TYPE_OP type=<root>.KRunnable origin=SAM_CONVERSION typeOperand=<root>.KRunnable
GET_VAR 'function: kotlin.Function0<kotlin.Unit> declared in <root>.test1a.KRunnable' type=kotlin.Function0<kotlin.Unit> origin=null
FUNCTION_REFERENCE 'local final fun KRunnable (function: kotlin.Function0<kotlin.Unit>): <root>.KRunnable declared in <root>.test1a' type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0<kotlin.Unit>, <root>.KRunnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget=<same>
FUN name:test1b visibility:public modality:FINAL <> () returnType:kotlin.reflect.KFunction<java.lang.Runnable>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test1b (): kotlin.reflect.KFunction<java.lang.Runnable> declared in <root>'
BLOCK type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0<kotlin.Unit>, java.lang.Runnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE
FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:Runnable visibility:local modality:FINAL <> (function:kotlin.Function0<kotlin.Unit>) returnType:java.lang.Runnable
VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function0<kotlin.Unit>
EXPRESSION_BODY
TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable
GET_VAR 'function: kotlin.Function0<kotlin.Unit> declared in <root>.test1b.Runnable' type=kotlin.Function0<kotlin.Unit> origin=null
FUNCTION_REFERENCE 'local final fun Runnable (function: kotlin.Function0<kotlin.Unit>): java.lang.Runnable declared in <root>.test1b' type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0<kotlin.Unit>, java.lang.Runnable> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget=<same>
FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Function1<kotlin.Function0<kotlin.String>, <root>.KSupplier<kotlin.String>>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test2 (): kotlin.Function1<kotlin.Function0<kotlin.String>, <root>.KSupplier<kotlin.String>> declared in <root>'
BLOCK type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0<kotlin.String>, <root>.KSupplier<kotlin.String>> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE
FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:KSupplier visibility:local modality:FINAL <> (function:kotlin.Function0<kotlin.String>) returnType:<root>.KSupplier<kotlin.String>
VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function0<kotlin.String>
EXPRESSION_BODY
TYPE_OP type=<root>.KSupplier<kotlin.String> origin=SAM_CONVERSION typeOperand=<root>.KSupplier<kotlin.String>
GET_VAR 'function: kotlin.Function0<kotlin.String> declared in <root>.test2.KSupplier' type=kotlin.Function0<kotlin.String> origin=null
FUNCTION_REFERENCE 'local final fun KSupplier (function: kotlin.Function0<kotlin.String>): <root>.KSupplier<kotlin.String> declared in <root>.test2' type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0<kotlin.String>, <root>.KSupplier<kotlin.String>> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget=<same>
FUN name:test2a visibility:public modality:FINAL <> () returnType:kotlin.Function1<kotlin.Function0<kotlin.String>, <root>.KSupplier<kotlin.String>>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test2a (): kotlin.Function1<kotlin.Function0<kotlin.String>, <root>.KSupplier<kotlin.String>> declared in <root>'
BLOCK type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0<kotlin.String>, <root>.KSupplier<kotlin.String>> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE
FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:KSupplier visibility:local modality:FINAL <> (function:kotlin.Function0<kotlin.String>) returnType:<root>.KSupplier<kotlin.String>
VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function0<kotlin.String>
EXPRESSION_BODY
TYPE_OP type=<root>.KSupplier<kotlin.String> origin=SAM_CONVERSION typeOperand=<root>.KSupplier<kotlin.String>
GET_VAR 'function: kotlin.Function0<kotlin.String> declared in <root>.test2a.KSupplier' type=kotlin.Function0<kotlin.String> origin=null
FUNCTION_REFERENCE 'local final fun KSupplier (function: kotlin.Function0<kotlin.String>): <root>.KSupplier<kotlin.String> declared in <root>.test2a' type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function0<kotlin.String>, <root>.KSupplier<kotlin.String>> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget=<same>
FUN name:test3 visibility:public modality:FINAL <> () returnType:kotlin.Function1<kotlin.Function1<kotlin.String, kotlin.Unit>, <root>.KConsumer<kotlin.String>>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test3 (): kotlin.Function1<kotlin.Function1<kotlin.String, kotlin.Unit>, <root>.KConsumer<kotlin.String>> declared in <root>'
BLOCK type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String, kotlin.Unit>, <root>.KConsumer<kotlin.String>> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE
FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:KConsumer visibility:local modality:FINAL <> (function:kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String, kotlin.Unit>) returnType:<root>.KConsumer<kotlin.String>
VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String, kotlin.Unit>
EXPRESSION_BODY
TYPE_OP type=<root>.KConsumer<kotlin.String> origin=SAM_CONVERSION typeOperand=<root>.KConsumer<kotlin.String>
GET_VAR 'function: kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String, kotlin.Unit> declared in <root>.test3.KConsumer' type=kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String, kotlin.Unit> origin=null
FUNCTION_REFERENCE 'local final fun KConsumer (function: kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String, kotlin.Unit>): <root>.KConsumer<kotlin.String> declared in <root>.test3' type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String, kotlin.Unit>, <root>.KConsumer<kotlin.String>> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget=<same>
FUN name:test3a visibility:public modality:FINAL <> () returnType:kotlin.Function1<kotlin.Function1<kotlin.String, kotlin.Unit>, <root>.KConsumer<kotlin.String>>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test3a (): kotlin.Function1<kotlin.Function1<kotlin.String, kotlin.Unit>, <root>.KConsumer<kotlin.String>> declared in <root>'
BLOCK type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String, kotlin.Unit>, <root>.KConsumer<kotlin.String>> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE
FUN ADAPTER_FOR_FUN_INTERFACE_CONSTRUCTOR name:KConsumer visibility:local modality:FINAL <> (function:kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String, kotlin.Unit>) returnType:<root>.KConsumer<kotlin.String>
VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:function index:0 type:kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String, kotlin.Unit>
EXPRESSION_BODY
TYPE_OP type=<root>.KConsumer<kotlin.String> origin=SAM_CONVERSION typeOperand=<root>.KConsumer<kotlin.String>
GET_VAR 'function: kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String, kotlin.Unit> declared in <root>.test3a.KConsumer' type=kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String, kotlin.Unit> origin=null
FUNCTION_REFERENCE 'local final fun KConsumer (function: kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String, kotlin.Unit>): <root>.KConsumer<kotlin.String> declared in <root>.test3a' type=kotlin.reflect.KFunction1<@[ParameterName(name = 'function')] kotlin.Function1<@[ParameterName(name = 'x')] kotlin.String, kotlin.Unit>, <root>.KConsumer<kotlin.String>> origin=FUN_INTERFACE_CONSTRUCTOR_REFERENCE reflectionTarget=<same>
@@ -0,0 +1,36 @@
// !LANGUAGE: +AllowKotlinFunInterfaceConstructorReference
// WITH_REFLECT
import kotlin.reflect.*
fun interface KRunnable {
fun run()
}
typealias KR = KRunnable
fun interface KSupplier<T> {
fun get(): T
}
typealias KSS = KSupplier<String>
fun interface KConsumer<T> {
fun accept(x: T)
}
typealias KCS = KConsumer<String>
fun test1() = ::KRunnable
fun test1a() = ::KR
fun test1b(): KFunction<Runnable> = ::Runnable
fun test2(): (() -> String) -> KSupplier<String> = ::KSupplier
fun test2a(): (() -> String) -> KSupplier<String> = ::KSS
fun test3(): ((String) -> Unit) -> KConsumer<String> = ::KConsumer
fun test3a(): ((String) -> Unit) -> KConsumer<String> = ::KCS
@@ -0,0 +1,74 @@
fun interface KRunnable {
abstract fun run()
}
typealias KR = KRunnable
fun interface KSupplier<T : Any?> {
abstract fun get(): T
}
typealias KSS = KSupplier<String>
fun interface KConsumer<T : Any?> {
abstract fun accept(x: T)
}
typealias KCS = KConsumer<String>
fun test1(): KFunction1<@ParameterName(name = "function") Function0<Unit>, KRunnable> {
return { // BLOCK
local fun KRunnable(fn: Function0<Unit>): KRunnable fn /*-> KRunnable */
::KRunnable
}
}
fun test1a(): KFunction1<@ParameterName(name = "function") Function0<Unit>, KRunnable> {
return { // BLOCK
local fun KRunnable(fn: Function0<Unit>): KRunnable fn /*-> KRunnable */
::KRunnable
}
}
fun test1b(): KFunction<Runnable> {
return { // BLOCK
local fun Runnable(fn: Function0<Unit>): Runnable fn /*-> Runnable */
::Runnable
}
}
fun test2(): Function1<Function0<String>, KSupplier<String>> {
return { // BLOCK
local fun KSupplier(fn: Function0<String>): KSupplier<String> fn /*-> KSupplier<String> */
::KSupplier
}
}
fun test2a(): Function1<Function0<String>, KSupplier<String>> {
return { // BLOCK
local fun KSupplier(fn: Function0<String>): KSupplier<String> fn /*-> KSupplier<String> */
::KSupplier
}
}
fun test3(): Function1<Function1<String, Unit>, KConsumer<String>> {
return { // BLOCK
local fun KConsumer(fn: Function1<@ParameterName(name = "x") String, Unit>): KConsumer<String> fn /*-> KConsumer<String> */
::KConsumer
}
}
fun test3a(): Function1<Function1<String, Unit>, KConsumer<String>> {
return { // BLOCK
local fun KConsumer(fn: Function1<@ParameterName(name = "x") String, Unit>): KConsumer<String> fn /*-> KConsumer<String> */
::KConsumer
}
}
@@ -1394,6 +1394,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest {
runTest("compiler/testData/ir/irText/expressions/funImportedFromObject.kt");
}
@Test
@TestMetadata("funInterfaceConstructorReference.kt")
public void testFunInterfaceConstructorReference() throws Exception {
runTest("compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.kt");
}
@Test
@TestMetadata("genericConstructorCallWithTypeArguments.kt")
public void testGenericConstructorCallWithTypeArguments() throws Exception {
@@ -1077,6 +1077,11 @@ public class KlibTextTestCaseGenerated extends AbstractKlibTextTestCase {
runTest("compiler/testData/ir/irText/expressions/funImportedFromObject.kt");
}
@TestMetadata("funInterfaceConstructorReference.kt")
public void testFunInterfaceConstructorReference() throws Exception {
runTest("compiler/testData/ir/irText/expressions/funInterfaceConstructorReference.kt");
}
@TestMetadata("genericConstructorCallWithTypeArguments.kt")
public void testGenericConstructorCallWithTypeArguments() throws Exception {
runTest("compiler/testData/ir/irText/expressions/genericConstructorCallWithTypeArguments.kt");