google / google/ksp

Declaration-site annotation targets are not respected

Open
#2,987 0 comments 0 reactions 0 assignees View on GitHub
bug core P3
Dominant language
Kotlin
Stars
3.5k
Forks
415
Avg merge
1d 2h
Merged PRs (30d)
53

Description

KSP does not currently consider the meta annotation `@Target` on declared annotations. For instance, KSP will return a property annotated with an annotation that only targets classes:
```kotlin
@Target(AnnotationTarget.CLASS)
annotation class Anno

// Here we expect KSP to only return Main on Resolver.getSymbolsWithAnnotation("Anno")
// but it returns both Main and Main.annotatedProperty.
@Anno
class Main {
@Anno
val annotatedProperty = 1
}
```
However, considering that this has always been KSP's behavior, is this change something we should even consider? Doing so could break a lot of downstream builds. How do symbol processors deal with this? Is this entirely ignored?

EDIT: This is definitely a bug, but Kotlinc will yield an error, so while KSP may succeed there is not silent failure.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.