Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Kotlin interface with @Module doesn't compile #80

Closed
NikolayKul opened this issue Dec 15, 2018 · 2 comments
Closed

Kotlin interface with @Module doesn't compile #80

NikolayKul opened this issue Dec 15, 2018 · 2 comments

Comments

@NikolayKul
Copy link

NikolayKul commented Dec 15, 2018

ViewModel:

class FeedDetailsViewModel @AssistedInject constructor(
    @Assisted private val feedId: FeedId,
    private val getFeedUseCase: GetFeedUseCase
) : BaseViewModel() {
    ...
    @AssistedInject.Factory
    interface Factory {
        fun create(feedId: FeedId): FeedDetailsViewModel
    }
}

Generated factory:

public final class FeedDetailsViewModel_AssistedFactory implements FeedDetailsViewModel.Factory {
  private final Provider<GetFeedUseCase> getFeedUseCase;

  @Inject
  public FeedDetailsViewModel_AssistedFactory(Provider<GetFeedUseCase> getFeedUseCase) {
    this.getFeedUseCase = getFeedUseCase;
  }

  @Override
  public FeedDetailsViewModel create(FeedId feedId) {
    return new FeedDetailsViewModel(
        feedId,
        getFeedUseCase.get());
  }
}

Module:

@Module
interface FeedDetailsActivityModuleKotlin {
    @Binds
    fun viewModelFactory(factory: FeedDetailsViewModel_AssistedFactory): FeedDetailsViewModel.Factory
}

Build fails with the following error:

e: /app/build/tmp/kapt3/stubs/debug/../FeedDetailsActivityModuleKotlin.java:11: error: @Binds methods must have only one parameter whose type is assignable to the return type
    public abstract com.nikolaykul.sebastian.presentation.feed.details.FeedDetailsViewModel.Factory viewModelFactory(@org.jetbrains.annotations.NotNull()

A few notes:

  1. Java version of the same Module builds fine:
@Module
public interface FeedDetailsActivityModuleJava {
    @Binds
    FeedDetailsViewModel.Factory viewModuleFactory(FeedDetailsViewModel_AssistedFactory factory);
}
  1. Using @AssistedModule builds fine as well. I guess thats because it generates java-code:
@AssistedModule
@Module(includes = [AssistedInject_ViewModelModule::class])
interface ViewModelModule

How can I fix it? 🤔

@JakeWharton
Copy link
Contributor

This error message comes from Dagger itself and not this library. Make sure you're using the latest version first, and then otherwise I would file an issue on the Dagger project if it persists. This library doesn't have a way to affect this behavior.

@VincentMasselis
Copy link

Unfortunately, even 2 years after this post, It's my turn to face this bug with the latest Dagger2 version (2.29.1)
@JakeWharton do you still consider creating an issue on their bug tracker ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants