I am using `buildArrayliteral {}` to populate an a...
# compiler
j
I am using
buildArrayliteral {}
to populate an array of an annotation I am trying to build this:
Copy code
@Database(
    entities = [
        OneEntity::class,
        TwoEntity:class,
    ]
)
abstract class FooDatabase : RoomDatabase()
Everything is created, but building the arrow with the function above fails due `Expected expression
FirArrayLiteralImpl
to be resolved`. But I do not find a way to resolve this expression.
d
• write such a literal in the code • stop in the debugger after resolve and check the exact content of
FirArrayLiteralImpl
properties • create the same in your plugin
j
I was missing the
coneType
, thought it was inferred by the list of arguments Additionally, to create that array of kclass, I am using
buildClassReferenceExpression
so:
Copy code
val entitiesClassReferences: List<FirClassReferenceExpression> =
        entities
            .map {
                buildClassReferenceExpression {
                    coneTypeOrNull = it.defaultType()
                    classTypeRef = buildResolvedTypeRef { coneType = it.defaultType() }
                }
            }
            .toList()
But it is failing with
Copy code
Should not be here: class org.jetbrains.kotlin.fir.expressions.impl.FirClassReferenceExpressionImpl <getClass>(R|com/qonto/dev/app/common/one/Param1|)
java.lang.IllegalStateException: Should not be here: class org.jetbrains.kotlin.fir.expressions.impl.FirClassReferenceExpressionImpl <getClass>(R|com/qonto/dev/app/common/one/Param1|)
	at org.jetbrains.kotlin.fir.backend.Fir2IrVisitor.visitElement(Fir2IrVisitor.kt:103)
Is it a valid approach or should I use a different thing?
d
> thought it was inferred by the list of arguments Nothing is getting inferred for generated elements. > Is it a valid approach or should I use a different thing? The node is correct. The
coneTypeOrNull
should be
KClass<out YourClass>
, not
YourClass
though. In general, the approach from my previous message valid in this case too.
👀 1
j
It is using
*
, I need to change it from
KClass<*>
to
KClass<Out *>
?
d
KClass<*>
is fine.
j
Looks like writing the original code uses
FirGetClassCallImpl
instead of
FirClassReferenceExpressionImpl
, is there an easy way to convert to the
FirGetClassCall
?
d
Oh, the
FirClassReferenceExpression
is used for annotation arguments on declarations deserialized from dependencies. For source you indeed need to use
FirGetClassCall
. There is no conversion between them as they never appear together.
👍 1
j
Thank you! It worked 🙂 Do you know if we will get
create*
like functions? My premise is avoiding using
build*
function as they are for internal things, but adding/replacing annotation means using multiple
build*
functions
d
Potentially yes. But no promises yet.