You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you don't specify a use-site target, the target is chosen according to the @target annotation of the annotation being used. If there are multiple applicable targets, the first applicable target from the following list is used:
param
property
field
Therefore, when an annotation with @target including "PARAMETER" is applied to a constructor property, it should be applied on the parameter KSNode not the property KSNode
However, in ksp2, it seems applied on both the parameter and the property
I notice this only happens when the annotation is declared in java
Repro
3097d3b : I created an java JavaAnnoWithParamAndFieldTarget and an kotlin annotation AnnoWithParamAndFieldTarget, both have @target include both field and parameter. And then i applied both on a constructor property fullName
Expected
Property fullName should have neither JavaAnnoWithParamAndFieldTarget nor AnnoWithParamAndFieldTarget.
Param fullName should be both JavaAnnoWithParamAndFieldTarget and AnnoWithParamAndFieldTarget
Actual
Property fullName have JavaAnnoWithParamAndFieldTarget
Param fullName have both JavaAnnoWithParamAndFieldTarget and AnnoWithParamAndFieldTarget
org.opentest4j.AssertionFailedError:
expected: <Annotation on property: Anno
true
Annotation on constructor param: Anno
Annotation on constructor param: AnnoWithParamAndFieldTarget
Annotation on constructor param: JavaAnnoWithParamAndFieldTarget
true>
but was: <Annotation on property: Anno
Annotation on property: JavaAnnoWithParamAndFieldTarget
true
Annotation on constructor param: Anno
Annotation on constructor param: AnnoWithParamAndFieldTarget
Annotation on constructor param: JavaAnnoWithParamAndFieldTarget
true>
only checked Kotlin annotation target "kotlin.annotation.Target", but not java annotation target
(Unrelated question for that line of code is: shouldn't this filterNot only happens if ktPropertySymbol.isFromPrimaryConstructor, cause only constructor property have both property and param node? This didn't cause any bug for me just curious. Thanks feel free to ignore.)
The text was updated successfully, but these errors were encountered:
In short #1302 still exist in KSP2, but i think only if the annotation is declared in java
Long explanation:
Base on https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets
Therefore, when an annotation with @target including "PARAMETER" is applied to a constructor property, it should be applied on the parameter KSNode not the property KSNode
However, in ksp2, it seems applied on both the parameter and the property
I notice this only happens when the annotation is declared in java
Repro
3097d3b : I created an java
JavaAnnoWithParamAndFieldTarget
and an kotlin annotationAnnoWithParamAndFieldTarget
, both have @target include both field and parameter. And then i applied both on a constructor propertyfullName
Expected
fullName
should have neitherJavaAnnoWithParamAndFieldTarget
norAnnoWithParamAndFieldTarget
.fullName
should be bothJavaAnnoWithParamAndFieldTarget
andAnnoWithParamAndFieldTarget
Actual
fullName
haveJavaAnnoWithParamAndFieldTarget
fullName
have bothJavaAnnoWithParamAndFieldTarget
andAnnoWithParamAndFieldTarget
Suggested fix
After debug, i think it's because
ksp/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyDeclarationImpl.kt
Lines 71 to 79 in ece7ae3
"kotlin.annotation.Target"
, but not java annotation target(Unrelated question for that line of code is: shouldn't this
filterNot
only happens ifktPropertySymbol.isFromPrimaryConstructor
, cause only constructor property have both property and param node? This didn't cause any bug for me just curious. Thanks feel free to ignore.)The text was updated successfully, but these errors were encountered: