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

Incorrect factory generated for class with type parameters #91

Closed
quiro91 opened this issue Sep 1, 2020 · 3 comments · Fixed by #92 or #95
Closed

Incorrect factory generated for class with type parameters #91

quiro91 opened this issue Sep 1, 2020 · 3 comments · Fixed by #92 or #95
Assignees
Labels
bug Something isn't working dagger factory Happens when generateDaggerFactories is set to true

Comments

@quiro91
Copy link
Contributor

quiro91 commented Sep 1, 2020

Given I have a class with a type parameter:

abstract class MyFragment<T> : Fragment() {

    @Inject
    lateinit var something: Something

Anvil will generated a factory as:

class MyFragment_MembersInjector(
        private val param0: Provider<Something>
) : MembersInjector<MyFragment> {
    override fun injectMembers(instance: MyFragment) {
        injectSomething(instance, param0.get())
    }

    companion object {
        @JvmStatic
        fun create(param0: Provider<Something>): MyFragment_MembersInjector =
            MyFragment_MembersInjector(param0)

        @JvmStatic
        @InjectedFieldSignature("com.foo.MyFragment")
        fun injectSomething(instance: MyFragment, something: Something) {
            instance.something = something
        }
    }
}

which doesn't compile. I'm no expert, but I believe adding a <*> to the generated code when there's a type parameter should be enough to fix this

@vRallev vRallev self-assigned this Sep 1, 2020
@vRallev vRallev added bug Something isn't working dagger factory Happens when generateDaggerFactories is set to true labels Sep 1, 2020
vRallev added a commit that referenced this issue Sep 1, 2020
@quiro91
Copy link
Contributor Author

quiro91 commented Sep 1, 2020

Thanks for taking care of this @vRallev, and thank you for Anvil, it's an awesome tool

@vRallev
Copy link
Collaborator

vRallev commented Sep 1, 2020

Thanks for the easy sample to reproduce the issue.

@quiro91
Copy link
Contributor Author

quiro91 commented Sep 2, 2020

I was trying version 2.0.2, it fixed most of the issues I've found, but the fix only works for single generic type. Opening a PR to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dagger factory Happens when generateDaggerFactories is set to true
Projects
None yet
2 participants