google/dagger

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

Opened this issue · 1 comments

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>> {
  // ...
}

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