https://kotlinlang.org logo
#compiler
Title
# compiler
z

Zac Sweers

02/24/2024, 8:17 PM
How are generic annotations' type parameters stored in metadata? I'm trying to resolve them at runtime with kotlin-reflect but finding that this information appears to always be missing and unavailable in kotlinx-metadata
m

Manuel Wrage

02/24/2024, 11:43 PM
They aren't stored unfortunately.
z

Zac Sweers

02/25/2024, 12:03 AM
Interesting, as I’m able to read them from an IR plugin
m

Manuel Wrage

02/25/2024, 7:17 AM
Before or after deserialization? The compiler has the information for currently compiled declarations, but the type argument information is lost if you look up already compiled declarations (from different modules or other incremental compilation rounds). I had to add super hacky workarounds to my compiler plugin because it relies on annotations with type arguments. Basically I store all types(parameter types, return types) of the declaration (function, property, class) in a json string and add a annotation with the json string to the declaration itself. Then later in different compilations I can read the annotation with the correct types. You can check it out here: https://github.com/IVIanuu/injekt/blob/master/compiler/src/main/kotlin/com/ivianuu/injekt/compiler/frontend/InfoPatcher.kt
z

Zac Sweers

02/25/2024, 10:07 PM
Ahh good point, I guess this would be before serialization