min
09/16/2026, 8:59 AMmaybeAnnotatedClass
.getAnnotationByClassId(
classId = ANNOTATION_CLASS,
session = session,
)
.coalesce { return Either.Bar(FactoryError.ClassNotAnnotated) }
.getKClassArgument(ANNOTATION_ARG)
.coalesce { return Either.Bar(FactoryError.ArgumentMissing) }
.classId
.coalesce { return Either.Bar(FactoryError.ArgumentInvalid) }
Is it ever possible for classId to be null when the call to getKClassArgument has succeeded?min
09/16/2026, 9:01 AMpublic annotation class MyAnnotation(val kClass: KClass<*>)
This is the annotation type definition the plugin tries to read.
inline fun <T: Any> T?.coalesce(fallback: () -> T): T {
return this ?: fallback()
}
Also, this is the definition of the coalesce utility in use.dmitriy.novozhilov
09/16/2026, 9:04 AMfun <T> foo(@Ann((T & Any)::class) x: Int) {}min
09/16/2026, 9:07 AM(T & Any)::class
What am I looking at here? & isn’t listed on kotlinlang.org/docs/keyword-reference.html#…dmitriy.novozhilov
09/16/2026, 9:09 AMdmitriy.novozhilov
09/16/2026, 9:10 AMfun <T> foo(@Anno(T::class) x: Int) {}min
09/16/2026, 9:15 AMannotation class is actually @Target(AnnotationTarget.CLASS).
@Target(AnnotationTarget.CLASS)
public annotation class MyAnnotation(val kClass: KClass<*>)
Can classId still be null after a successful call to getKClassArgument?
maybeAnnotatedClass
.getAnnotationByClassId(
classId = ANNOTATION_CLASS,
session = session,
)
.coalesce { return Either.Bar(FactoryError.ClassNotAnnotated) }
.getKClassArgument(ANNOTATION_ARG)
.coalesce { return Either.Bar(FactoryError.ArgumentMissing) }
.classId
.coalesce { return Either.Bar(FactoryError.ArgumentInvalid) }dmitriy.novozhilov
09/16/2026, 9:17 AMclass Outer<T> {
@Ann(T::class)
inner class Inner
}
Also note, that annotation target doesn't prevent user to write the annotation anywhere. It prevents this code to be compiled (passed to backend). The frontend would still resolve it.