Hello! How can i generate lambda function at comi...
# compiler
p
Hello! How can i generate lambda function at comiler ir phase? I'm transforming function body and want to assign lambda to variable. That lambda must be my generated lambda. I found IrFunctionImpl class that i can use for that, but it has parameter of FunctionDescriptor. But to create it, i need to specify containing declaration, but in M3 links to frontend structures were removed or deprecated.
r
First, general way to create a lambda function is to use
IrFunctionExpression
. As descriptor you could use
WrappedSimpleFunctionDescriptor
or even build
IrSimpleFunction
with
IrFunctionBuilder
p
@Roman Artemev [JB] Thanks for reply! I see that in IrModuleFragment property descriptor is not deprecated. Will it be?
👌 1
One more question: pluginContext.referenceClass("kotlin.UnsupportedOperationException") returns null. Is this method search only in current module symbols? If so how can I reference class from dependency module?
r
You are doing everything right. Looks looks a bug
pluginContext.referenceClass
searches among module dependencies too. Actually it is a recommended way to access external symbols. Could you please find an issue in YT with it?
p
I can't find one. I guess it is related to typealias. Cause kotlin.IllegalStateException is a typealias for jvm to java.lang.IllegalStateException. Does typealias resolves on pluginContext.referenceClass? I can't find method where typealias mentions.
r
Ohh, yeah. It seems to be. Is that JVM platform?
No, it’s not right now. Please file an issue-request. Will try to support soon. BTW, does
pluginContext.referenceClass("java.lang.UnsupportedOperationException")
work for you?
p
I reproduced with class in the same module but typealiased. Use IR -> JVM
r
Yeah, it is lack of implementation in our API. We’re going to fix it soon.
p