Skip to content

[KSP2] KSAnnotations with KClass properties with a default value always resolve to error types #1842

@ZacSweers

Description

@ZacSweers

Tested with 2.0.0-RC1-1.0.20

Given an annotation like so:

annotation class Example(
  val someClass: KClass<*> = String::class,
  val someClasses: Array<KClass<*>> = [String::class],
)

@Example
class SomeAnnotatedClass

When reading the annotation instance off of SomeAnnotatedClass in a processor, the String::class types are always error types. I discovered this while preparing KotlinPoet for K2, with a repro available in this PR in the TestProcessorTest.removeDefaultValues test. If you breakpoint the isDefaultValue() check in KSAnnotation.toAnnotationSpec(), you can verify this behavior.

I've also confirmed this happens even if you add an explicit kotlin.String import. This also is the case for the String::class inside an array, which similarly resolves to an error type.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    AAwaiting for upstream fixduplicateThis issue or pull request already exists

    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