Zac Sweers
03/01/2025, 8:34 PMArray<KClass<*>>
in an annotation to contain a mix of resolved and unresolved classes (from the command line)? I'm trying a to find a through-line that explains why some are unresolved while others that appear to follow the same structure are resolved. Or is it just down to which classes the compiler has seen up to that point?Zac Sweers
03/01/2025, 8:39 PMdmitriy.novozhilov
03/06/2025, 9:22 AMWhat scenarios in FIR would cause an Array<KClass<*>> in an annotation to contain a mix of resolved and unresolved classes (from the command line)?That sounds suspicious, at the supertypes stages no arguments should be resolved except some special cases (doc).
is there a way to defer my extension from running until all those arguments are resolved during supertype generation?There is no way, annotation arguments resolution is the last phase before
BODY_RESOLVE
(see the link above)Zac Sweers
03/06/2025, 7:03 PMZac Sweers
03/06/2025, 7:04 PMdmitriy.novozhilov
03/07/2025, 7:03 AMhm, even if the annotation itself is a predicate of the supertype generator?Yes.
COMPILER_REQUIRED_ANNOTATIONS
phase resolves just annotation types, not annotation argumentsdmitriy.novozhilov
03/07/2025, 7:10 AMI know IR in K2 does not allow modification of superinterfaces of user-defined sourcesNot sure, if it's true.
IrClass.superTypes
is var
, so you can replace the supertype list. But there would be a problem, that these changes woundn't be reflected in the metadata, because metadata generated based on FIR, not IR.
But there is a dirty hack: you can add new supertype both at IR and FIR at the same time. I cannot guarantee that it would work, but I don't see reasons why it shouldn't
fun test(irClass: IrClass, newType: IrSimpleType) {
irClass.superTypes += newType
val classId = newType.classOrNull?.owner?.classId ?: return
val arguments: List<ConeTypeProjection> = TODO() // convert in the same way as the type
val coneType = classId.toLookupTag().constructClassType(arguments.toTypedArray())
val typeRef = coneType.toFirResolvedTypeRef()
val firClass = (irClass.metadata as? FirMetadataSource.Class)?.fir ?: return
firClass.replaceSuperTypeRefs(firClass.superTypeRefs + typeRef)
}
Zac Sweers
03/07/2025, 7:12 PMZac Sweers
03/07/2025, 7:14 PMZac Sweers
03/07/2025, 7:14 PMZac Sweers
03/07/2025, 7:34 PMdmitriy.novozhilov
03/07/2025, 10:34 PM