Ayla
09/07/2023, 11:07 AMval f={}
->`val f={i:Int-> }` ,I tried this:
moduleFragment.transformChildrenVoid(object :
IrElementTransformerVoidWithContext() {
override fun visitFunctionExpression(expression: IrFunctionExpression): IrExpression {
expression.function.addValueParameter {
name= Name.identifier("i")
type=pluginContext.referenceClass(ClassId.fromString("<http://kotlin.Int|kotlin.Int>"))?.owner?.defaultType!!
}
return super.visitFunctionExpression(expression)
}
})
but got an error:
Caused by: java.lang.IllegalArgumentException: No argument for parameter VALUE_PARAMETER name:a index:0 type:<http://kotlin.Int|kotlin.Int>:
CALL 'public final fun invoke (a: <http://kotlin.Int|kotlin.Int>): kotlin.Unit declared in <root>.FileKt.<clinit>.<no name provided>' type=kotlin.Unit origin=BRIDGE_DELEGATION
$this: GET_VAR '<this>: <root>.FileKt.<clinit>.<no name provided> declared in <root>.FileKt.<clinit>.<no name provided>.invoke' type=<root>.FileKt.<clinit>.<no name provided> origin=null
I'm new to kotlin compiler plugin, and I'm confused as the function expression is not invoked,so where should I pass the argument ? Or the way I add the paramter is wrong?dmitriy.novozhilov
09/07/2023, 11:09 AMIrFunctionExpression
)
Note that after such transformation you need to update the type of each call-site of f
(and type of f
itself too)Ayla
09/07/2023, 4:31 PM