How do you reference another function (or wrap it ...
# compiler
n
How do you reference another function (or wrap it in a lambda) in IR? I have a
fun hello(who: String) = "Hello, $who!"
as a
IrSimpleFunction
. I need to pass this to a fun
process(function: (String) -> String)
, but I’m confused as to how to pass my function as a value argument to another. To be clear, in source code I’d do process(::hello) or process { hello(it) }.
s
You can take a look at
IrFunctionReference
, which backs up
::hello
syntax iirc
t
What I usually do is to write it in Kotlin and use
IrModuleFragment.dump()
how the IR looks like. From there it is usually easy to find the IR calls to build the given part.
n
Thanks a lot guys. dump is super useful. I also went a long way by just looking at autocompletion, e.g.
ir*
functions in declaration builder, or ir factory. For some reason function references are not advertised there though