Skip to content

Anvil fails to generate a MembersInjector for an inherited generic property #1040

@1gravity

Description

@1gravity

I have the following two classes:

open class BaseClass<T : Any> {
    @Inject
    lateinit var value: T
}

class Class : BaseClass<Feature>() {
    @Inject
    lateinit var feature: Feature
}

If Dagger is creating the factories, it compiles and runs. If I have Anvil create the factories the compilation fails with

Class_MembersInjector.kt:22:55 Unresolved reference: T

Kotlin: 1.9.23
Dagger: 2.51.1
Anvil: 2.5.0-beta10

The code above compiles with Anvil generating the factories if I remove either of the two injected fields. It also compiles if I change the type of the injected field to something else than the generic T.

I pushed the code to my test repo: https://github.com/1gravity/anvil-tests. The code is in the library module.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions