Hello all~ I'm new to K2 and learning about FirExp...
# compiler
n
Hello all~ I'm new to K2 and learning about FirExpression. If I want to build simple function as below in FIR
Copy code
fun simpleFunction(): Int = TODO()
How could I build expression to present
: Int = TODO()
in FirFunction? Try using example in https://github.com/JetBrains/kotlin/blob/master/docs/fir/fir-basics.md, I guess the direction is like
Copy code
val myFunction = buildSimpleFunction {
    name = Name.identifier("simpleFunction")
    ... << starting here I lose my direction in building return type, equal token and TODO() expression
}
If anyone could share me the pointer of simple examples FirExpression build will be great!
d
In the original design it's expected that on frontend you generate just functions/properties declaration (without body), and fill their bodies at the IR stage using
IrGenerationExtension
But if you really want to generate this call at frontend, you can just write
TODO()
call in the source code, inspect it's content in the debugger (e.g. by implementing some empty function call checker, which will be called on this call) and accordingly initialize all required fields in
buildFunctionCall
As for
buildSimpleFunction
, I don't recommend use it There is a bunch of different utilities for creation of declaration from plugins (named
create...
), and it's better to use them Check this file as an entrypoint And here is an usage example
❤️ 1
👍 1