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

Resolver returns non-equal instances of the same declaration. #2246

Closed
bcorso opened this issue Dec 2, 2024 · 2 comments · Fixed by #2301
Closed

Resolver returns non-equal instances of the same declaration. #2246

bcorso opened this issue Dec 2, 2024 · 2 comments · Fixed by #2301
Milestone

Comments

@bcorso
Copy link

bcorso commented Dec 2, 2024

In KSP1, all instance of a KSDeclaration for the same declaration were equal (this is a similar to the expectation in javac for Element instances).

However, in KSP2 we can get two different (non-equal) instances for the same declaration depending on if we get the instance using Resolver#getClassDeclarationByName() or Resolver#getSymbolsWithAnnotation(), e.g. suppose we have:

@MyAnnotation class MyClass

And the following processor:

  override fun process(resolver: Resolver): List<KSAnnotated> {
    val declaration1 = resolver.getSymbolsWithAnnotation("MyAnnotation").single()
    val declaration2 = resolver.getClassDeclarationByName( resolver.getKSNameFromString("MyClass"))!!
    println("declaration1.equals(declaration2): ${declaration1.equals(declaration2)}")
    return listOf()
  }

This results in:

// KSP1:
declaration1.equals(declaration2): true

// KSP2:
declaration1.equals(declaration2): false
@ting-yuan ting-yuan added this to the 1.0.30 milestone Jan 15, 2025
@bcorso
Copy link
Author

bcorso commented Jan 16, 2025

Update: Looks like this issue is specific to declarations in java sources (declarations from kotlin sources seem to work fine).

@ting-yuan
Copy link
Collaborator

Filed an upstream bug and working on workarounds.

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