:wave: I'm currently porting my K1 compiler plugi...
# compiler
j
👋 I'm currently porting my K1 compiler plugin to K2. I want to add a new function to a class. I replaced the
SyntheticResolveExtension
with a
FirDeclarationGenerationExtension
to add the signature. The Fir phase runs without exception, however the method is missing during Ir phase.
Copy code
override fun generateFunctions(
    callableId: CallableId,
    context: MemberGenerationContext?
  ): List<FirNamedFunctionSymbol> {
    val newFunction = buildSimpleFunction {
      moduleData = session.moduleData
      name = callableId.callableName
      dispatchReceiverType = context?.owner?.defaultType()
      symbol = FirNamedFunctionSymbol(callableId)
      origin = context!!.owner.origin // TODO
      status = FirResolvedDeclarationStatusImpl(Visibilities.Public, Modality.OPEN, EffectiveVisibility.Public)
      returnTypeRef = buildResolvedTypeRef { type = session.builtinTypes.unitType.type }
    }

    return listOf(newFunction.symbol)
  }
During class lowering I want to add the function body. However the method is missing in
irClass.functions
. Any ideas why?
a
It's possible that it's because you miss the body for the function. You can define it right there with FIR, or add to your plugin an IR extension and add the body on the IR side.
j
Hm, it works when I use
createMemberFunction
. Dunno what was missing with the other approach