When I use `FirDeclarationGenerationExtension.getC...
# compiler
t
When I use
FirDeclarationGenerationExtension.getCallableNamesForClass
I return with a
Set
. However, the order of the declarations would be important as one of the properties I generate use another I generate. The set does not keep the order, so, my code fails with
Parameter specified as non-null is null
. Should I reorder the declarations? Or do I do something wrong?
d
How this property depends on another? I see only two cases: • you generate the property with anonymous object in initializer and want to use it in the second property (which is quite a weird case) • you generate the body of the property in the frontend, which is not recommended
t
I generate the backing field of the property in backend IR. Only the declaration is generated in FIR. The value of the first property is result of a call that gets a constant string and returns an instance. The value of the second property uses the value of the first one.
d
The value of the second property uses the value of the first one.
Do you mean it is used in the initializer?
t
No, the initializer of the second calls the property getter of the first:
Copy code
irCall(
   companionClass.propertyGetter { Strings.ADAT_METADATA },
   irGet(companionClass.thisReceiver !!)
)
So, at the end it is like this, but generated.
Copy code
companion object {
  val a = 12
  val b = a + 12
}
d
And the problem is that after fir2ir those properties are generated in reversed order, right?
t
Yes. As I return with a set, there is no guarantee for the order.
d
You can reorder properties in
IrClass.declarations
manually
t
Yes, I coded that just now, it works.
Thanks.
👌 1