google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.44k stars 2.02k forks source link

DaggerKSP - Multibindings fail when a typealias is in use #4413

Open tinder-johnbuhanan2 opened 2 months ago

tinder-johnbuhanan2 commented 2 months ago

On 2.51.1, when we try switching to Dagger KSP, our compilation breaks with the following:

/../view/component/SomeView_MembersInjector.java:46: error: incompatible types: Map<SomeType1,CAP#1> cannot be converted to Map<SomeType1,SomeType2<?,?>>
    instance.viewBinderMap = viewBinderMap;
                             ^
  where CAP#1 is a fresh type-variable:
    CAP#1 extends SomeType2<?,?> from capture of ? extends SomeType2<?,?>
1 error

The offender looks like this:

internal typealias ViewBinder = SomeType2<*, *>

internal typealias ViewBinderMap =
    Map<@JvmSuppressWildcards SomeType1, @JvmSuppressWildcards ViewBinder>

@AndroidEntryPoint
internal class SomeView(context: Context, attributeSet: AttributeSet?) : RecyclerView(context, attributeSet) {

    @Inject
    lateinit var viewBinderMap: ViewBinderMap
...
}

If we take out the typealias then it starts working.

@AndroidEntryPoint
internal class SomeView(context: Context, attributeSet: AttributeSet?) : RecyclerView(context, attributeSet) {

    // Without typealiases, this is an eyesore.
    @Inject
    lateinit var viewBinderMap: Map<@JvmSuppressWildcards SomeType1, @JvmSuppressWildcards SomeType2<*, *>>
...
}
kuanyingchou commented 2 months ago

Hi, @tinder-johnbuhanan2 , somehow I couldn't reproduce it on my side. Is it possible to provide a minimal reproducible project?