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

LazyClassKey doesn't work when providing a Map<Class<*>, Provider<?> with a scope #4254

Closed
lwasyl opened this issue Mar 1, 2024 · 0 comments

Comments

@lwasyl
Copy link

lwasyl commented Mar 1, 2024

The following doesn't compile with Dagger KSP 2.51:

package com.example

import dagger.Component
import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoMap
import dagger.multibindings.LazyClassKey
import javax.inject.Inject
import javax.inject.Provider
import javax.inject.Qualifier
import javax.inject.Scope

@Component(modules = [TestModule::class])
@SomeScope
interface TestComponent {

    fun f(): F
}

@Module
internal class TestModule {

    @Provides
    @IntoMap
    @SomeQualifier
    @LazyClassKey(String::class)
    fun foo(): String = "foo"

    @Provides
    @IntoMap
    @SomeQualifier
    @LazyClassKey(TestModule::class)
    fun bar(): String = "foo"
}

@SomeScope
class F @Inject constructor(
    @SomeQualifier private val arg: @JvmSuppressWildcards Map<Class<*>, Provider<String>>,
)

@Qualifier
annotation class SomeQualifier

@Scope
annotation class SomeScope

with the following error:

build/generated/ksp/main/java/com/example/DaggerTestComponent.java:77: error: incompatible types: MapProviderFactory<String,String> cannot be converted to MapFactory<String,String>
      this.someQualifierMapOfClassOfAndProviderOfStringProvider = LazyClassKeyMap.Factory.<String>of(MapProviderFactory.<String, String>builder(2).put(LazyClassKeyProvider.java_lang_String, fooProvider).put(LazyClassKeyProvider.com_example_TestModule, barProvider).build());
                                                                                                                                                                                                                                                                              ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error

The above works if one of the following changes are made:

  • @ClassKey is used instead of @LazyClassKey
  • @SomeScope is not used
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 21, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
copybara-service bot pushed a commit that referenced this issue Mar 22, 2024
Will support producer in a follow up cl.

Fixes #4254

RELNOTES=n/a
PiperOrigin-RevId: 612518867
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.

1 participant