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

KSAnnotation.toAnnotationSpec() fails if the KSAnnotation is a typealias to another Annotation #1945

Closed
milis92 opened this issue Jul 17, 2024 · 1 comment · Fixed by #1956
Labels

Comments

@milis92
Copy link

milis92 commented Jul 17, 2024

Describe the bug

Consider following scenario:

annotation class SomeAnnotation
typealias SomeOtherAnnotation = SomeAnnotation

@SomeOtherAnnotation
fun doSomething() {
}

Calling KSAnnotation.toAnnotationSpec() on the doSomething function annotations, KSP will throw:

e: java.lang.ClassCastException: class com.google.devtools.ksp.impl.symbol.kotlin.KSTypeAliasImpl cannot be cast to class com.google.devtools.ksp.symbol.KSClassDeclaration (com.google.devtools.ksp.impl.symbol.kotlin.KSTypeAliasImpl and com.google.devtools.ksp.symbol.KSClassDeclaration are in unnamed module of loader 'app')
	at com.squareup.kotlinpoet.ksp.AnnotationsKt.toAnnotationSpec(Annotations.kt:48)
	at com.squareup.kotlinpoet.ksp.AnnotationsKt.toAnnotationSpec$default(Annotations.kt:35)...

Expected behavior

  • I would expect this to work, without errors.
  • KSAnnotation.toAnnotationSpec() should return resolved annotation

Additional context

val params = (annotationType.resolve().declaration as KSClassDeclaration).primaryConstructor?.parameters.orEmpty()

This seems like it should be a safe cast to KSClassDeclaration

@milis92 milis92 added the bug label Jul 17, 2024
@ZacSweers
Copy link
Collaborator

Thanks for the report, I've got a branch with a fix in the works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants