Checkers: drop use-site targets handling from repeated annotation checks (KT-85288)#6179
Checkers: drop use-site targets handling from repeated annotation checks (KT-85288)#6179Mikhail Glukhikh (mglukhikh) wants to merge 5 commits into
Conversation
Code Owners
|
35edbcc to
dad8fb1
Compare
| for (annotation in annotations) { | ||
| val useSiteTarget = annotation.useSiteTarget ?: expression.getDefaultUseSiteTarget(annotation) | ||
| val existingTargetsForAnnotation = annotationsMap.getOrPut(annotation.annotationTypeRef.coneType) { arrayListOf() } | ||
| val coneType = annotation.annotationTypeRef.coneType |
There was a problem hiding this comment.
Do we need to expand typealiases here? If yes, it might be a breaking change.
There was a problem hiding this comment.
Probably no, as the test below works, and it seems to me that we normally expand expression types beforehand. I will add the test to this MR to be more sure about correctness here.
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class A
typealias B = A
fun main() {
val x = @A @B 1 // This annotation is not repeatable
}
There was a problem hiding this comment.
JiC, the behavior might differ between regular tests and FirLightTreeDiagnosticsWithoutAliasExpansionTestGenerated.
There was a problem hiding this comment.
Yep, it's failing.
| } | ||
|
|
||
| checkDeclaredRepeatedAnnotations(declaration) | ||
| val annotations = declaration.annotations.filterNot { it in annotationsWithIncorrectTarget } |
There was a problem hiding this comment.
| val annotations = declaration.annotations.filterNot { it in annotationsWithIncorrectTarget } | |
| val annotations = declaration.annotations - annotationsWithIncorrectTarget |
There was a problem hiding this comment.
Applied manually
| if (annotation.source?.kind == KtFakeSourceElementKind.FromUseSiteTarget) return | ||
| ): Boolean { | ||
| if (annotation.source?.kind == KtFakeSourceElementKind.FromUseSiteTarget) return false | ||
| when (target) { |
There was a problem hiding this comment.
Can this be refactored to return when? Some branches look like they could be split into multiple ones with guards to make the change easier.
There was a problem hiding this comment.
I will refactor it (not sure it becomes much better).
Before this commit, we handled each pair (annotation, use-site target) separately during repeating checks. In fact, it's not needed, as annotations are moved to different declarations during earlier checks, so we dropped unnecessary complexity in this commit. #KT-85288 Fixed
Before this commit, we checked all existing annotations on repetition, including erroneous ones, forcing sometimes questionable reporting of REPEATED_ANNOTATION and particular corner-case checks. In this commit, we filter out all annotations with incorrect target before repetition checks, thus allowing to drop corner cases and having less questionable diagnostics. Related to KT-85288
dad8fb1 to
3feaa12
Compare
No description provided.