Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unresolvable class in annotation value is missing (rather than <ERROR TYPE>) when used in Kotlin sources. #1474

Closed
bcorso opened this issue Jul 21, 2023 · 0 comments · Fixed by #1490
Milestone

Comments

@bcorso
Copy link

bcorso commented Jul 21, 2023

To reproduce this, define an annotation that accepts Class<?>[]:
(Note: in this case its a Java annotation, but it can also be written in kotlin -- it doesn't affect the results in this case):

@interface MyAnnotation {
  Class<?>[] classes();
}

Next, use the annotation in a Kotlin source with a missing type, e.g.
(Note: this class must be written in Kotlin to demonstrate the bug):

@MyAnnotation(classes = [String::class, MissingType::class, Number::class])
class MyKotlinClass

Finally, print the annotation values with something like this:

val myClassName = resolver.getKSNameFromString("MyKotlinClass")
val myClass = resolver.getClassDeclarationByName(myClassName)
myClass?.annotations?.forEach { annotation ->
  println("${annotation.annotationType}: ${annotation.arguments.map { "${it.name?.asString()}: ${it.value}" }.toList() }")
}

This results in the following output:

MyAnnotation: [classes: [String, Number]]

Note that the MissingType class is just missing. At the very least I would expect it to show up as an <ERROR TYPE>.


Note that this only happens when the annotation is used in Kotlin source.

If we use the annotation in a Java source we get the correct results, e.g.

@MyAnnotation(classes = {String.class, MissingType.class, Number.class})
class MyJavaClass {}

Results in the expected output:

MyAnnotation: [classes: [String, <ERROR TYPE>, Number]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants