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

[KSP2] The order of symbols returned from Resolver.getSymbolsWithAnnotation() is different #1719

Closed
kuanyingchou opened this issue Feb 7, 2024 · 2 comments

Comments

@kuanyingchou
Copy link
Contributor

kuanyingchou commented Feb 7, 2024

Not sure if it's intended or a known issue but I couldn't find any doc explaining this.

Using Resolver.getSymbolsWithAnnotation() to get symbols annotated with TopLevelAnnotation on this code:

class Baz constructor(
    @param:TopLevelAnnotation val ctorProperty: String,
    @TopLevelAnnotation ctorParam: String
) {
    @setparam:TopLevelAnnotation
    var property: String = ""
    fun method(@TopLevelAnnotation methodParam: String) {}
}

returns [p0, methodParam, ctorProperty, ctorParam] in KSP 2 but was
[ctorProperty, ctorParam, p0, methodParam] in KSP 1

This can also be reproduced with testGetSymbolsFromAnnotation() in the KSP project, which is disabled in KSPAATest.kt.

Tested with 42217b8 and 2.0.0-Beta3-1.0.18-20240207.110119-15.

@neetopia
Copy link
Collaborator

neetopia commented Feb 7, 2024

Ordering is not a goal for consistency between KSP1 and KSP2, we do try out best to preserve same ordering between 2 implementations, if this ordering inconsistency is an issue for your implementation, we can try to fix it.

@kuanyingchou
Copy link
Contributor Author

Ah, thanks! I reported this because one of XProcessing's tests is failing, but while trying to find out whether the ordering is important I found that our function that wraps getSymbolsWithAnnotation is returning a Set already so the ordering shouldn't matter. Let me fix our test. Sorry for the noise. 🙏

copybara-service bot pushed a commit to androidx/androidx that referenced this issue Mar 12, 2024
XRoundEnvTest.getAnnotatedParamElements()

KSP2 doesn't guarantee the ordering of results from `Resolver.getSymbolsWithAnnotation()`[1] and our wrapper `XRoundEnv.getElementsAnnotatedWith()` is returning a `Set` anyway so we remove the ordering check in our test in this CL.

[1] google/ksp#1719

Test: XRoundEnvTest
Change-Id: Ib7865860214b76207c250b1d0ab257ef1cd4c2dd
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

No branches or pull requests

2 participants