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

[KSP] Intersection type bounds are not ordered correctly in generated factories #4345

Closed
ZacSweers opened this issue Jul 4, 2024 · 1 comment

Comments

@ZacSweers
Copy link

Given this snippet in Kotlin

abstract class Other

class InjectClass<T> @Inject constructor(
  private val t: T
) where T : Appendable, T : Other

Dagger generates a factory in KSP like so

public final class InjectClass_Factory<T extends Appendable & Other> implements Factory<InjectClass<T>> {
  // ...
}

This code however doesn't compile, because while Kotlin allows for the class bound to be in any order, Java requires it to be the first type. That is to say, the generated code should actually be.

public final class InjectClass_Factory<T extends Other & Appendable> implements Factory<InjectClass<T>> {
  // ...
}
copybara-service bot pushed a commit to androidx/androidx that referenced this issue Jul 10, 2024
In Java a class type parameter bound should go before interface bounds.
Here we make an extra sorting in KspTypeParameterElement.bounds to ensure that. Though this ordering could be different from the declaration order in Kotlin, it makes codegen easier and also makes the behavior a bit more consistent with KAPT.

Test: XTypeParameterElementTest
Bug: google/dagger#4345
Change-Id: Ifd766607dab08235df2565dc1b964d4293289af9
@kuanyingchou
Copy link
Collaborator

Thanks for the report! The fix is now merged to a library Dagger uses and should be included in the next Dagger release.

copybara-service bot pushed a commit that referenced this issue Jul 11, 2024
This pulls in the fix for #4345 from the XProcessing library.

Fixes #4345

RELNOTES=Fixed #4345
PiperOrigin-RevId: 651428354
copybara-service bot pushed a commit that referenced this issue Jul 11, 2024
This pulls in the fix for #4345 from the XProcessing library.

Fixes #4345

RELNOTES=Fixed #4345
PiperOrigin-RevId: 651428354
copybara-service bot pushed a commit that referenced this issue Jul 11, 2024
This pulls in the fix for #4345 from the XProcessing library.

Fixes #4345

RELNOTES=Fixed #4345
PiperOrigin-RevId: 651428354
copybara-service bot pushed a commit that referenced this issue Jul 11, 2024
This pulls in the fix for #4345 from the XProcessing library.

Fixes #4345

RELNOTES=Fixed #4345
PiperOrigin-RevId: 651428354
copybara-service bot pushed a commit that referenced this issue Jul 11, 2024
This pulls in the fix for #4345 from the XProcessing library.

Fixes #4345

RELNOTES=Fixed #4345
PiperOrigin-RevId: 651428354
@bcorso bcorso closed this as completed Aug 5, 2024
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.

3 participants