My IR backend plugin adds a companion object to cl...
# compiler
t
My IR backend plugin adds a companion object to classes. The companion is added, generated, all the tests work well. However, when I publish the module with the added companions and then try to access that companion from the plugin, they are is missing. Is there a trick to add companions properly? I just create the companion, set the parent to the class and add it to the declarations of the class. I've checked on JVM and the
Original$Companion.class
file is there and it contains the code I generated.
y
If you mean that you're trying to access the companions in a consumer of the generated JAR, then likely you need a FIR plugin to declare that you're generating that companion. I'm on mobile rn, but if you search this channel for FIR docs you should be able to find the Declaration Generation Extension or whatever it's called
thank you color 1
j
Hi, I came across similar issue recently (I needed to generate a method inside a class, but I think it would be similar for Companion) I solved it by using
SyntheticResolveExtension
to declare this method and then
IrGenerationExtension
to generate its body. If
SyntheticResolveExtension
won’t help you here then maybe
FirDeclarationGenerationExtension
would (as mentioned by Youssef).
thank you color 1
t
Adding the companion with the
FirDeclarationGenerationExtension
solved the problem. Thanks.
f
Do you remember how did you add the companion object in
FirDeclarationGenerationExtension
? It is not obvious to me how to do that