Johannes Barop
12/19/2022, 11:50 PMforEach
. I have difficulties setting the "action" parameter.
This is the IR-dump I want to generate:
action: FUN_EXPR type=kotlin.Function1<String, kotlin.Unit> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (it:String) returnType:kotlin.Unit
VALUE_PARAMETER name:it index:0 type:String
BLOCK_BODY
However, I can't get it to create a FUN_EXPR
of type kotlin.Function1<String, kotlin.Unit>
. Is irFactory.buildFun
the proper approach?
Thats the current code - which does not work -
putValueArgument(0, irBlock(
origin = IrStatementOrigin.LAMBDA,
resultType = context.irBuiltIns.unitType,
) {
+pluginContext.irFactory.buildFun {
name = Name.identifier("")
type = context.irBuiltIns.getKFunctionType(
returnType = context.irBuiltIns.unitType,
parameterTypes = listOf(context.irBuiltIns.stringType)
)
visibility = DescriptorVisibilities.LOCAL
modality = Modality.FINAL
origin = IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
}.also {
it.dispatchReceiverParameter = null
it.extensionReceiverParameter = null
it.body = irBlockBody { }
}
})
Which generates following IR
action: BLOCK type=kotlin.Unit origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:<Uninitialized>
BLOCK_BODY
Any hints or clues?rnett
12/19/2022, 11:54 PMIrFunctionExpression
, and pass that as the argument. This is a now quite out of date function I had to do that. Last time I was working with IR you also had to explicitly set the return type of the lambda