Skip to content

[KSP2] Annotation missing from property when VALUE_PARAMETER target is used. #2358

@bcorso

Description

@bcorso

Consider the following sources:

@Target(PROPERTY, VALUE_PARAMETER)
annotation class MyAnnotation

class MyClass {
  @MyAnnotation lateinit var str: String
}

And the following processor logic:

val myClassName = resolver.getKSNameFromString("MyClass")
val myClass: KSClassDeclaration = resolver.getClassDeclarationByName(myClassName)!!
val prop = myClass.getAllProperties().single()

println("${prop}: ${prop.annotations.map { it.shortName.asString() }.toList()}")

This results in the following outputs:

# KSP1
prop: [MyAnnotation]

# KSP2
prop: []

In particular, the MyAnnotation is missing from the property in KSP2.

Note that if we remove VALUE_PARAMETER from the target the annotation shows up on the property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions