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

MembersInjector's constructor has wrong parameter order when base class with @Inject fields is in another module #723

Open
matejdro opened this issue Jul 13, 2023 · 1 comment

Comments

@matejdro
Copy link

matejdro commented Jul 13, 2023

When:

  1. You have a class and subclass that both inject something with @Inject
  2. Both of those classes are in separate modules that only run anvil (with factory generation)
  3. You attempt to get a MembersInjector for that class

Build will fail with incompatible types exception. It seems like the order of parameters in MembersInjector generated by Anvil is not the same as expected by Dagger.

Steps to reproduce:

Run this test: matejdro@df9e78a

OR

  1. Checkout https://github.com/matejdro/issues/tree/anvil-field-injection-subclass
  2. Run ./gradlew assembleDebug

This situation seems weirdly specific at first, but getting MembersInjector strategy is used by Whestone to allow activity injection. Concretely, this bug means that we cannot have an activity where both actual activity and its parent class inject things independently.

matejdro added a commit to matejdro/anvil that referenced this issue Jul 17, 2023
@matejdro
Copy link
Author

matejdro commented Jul 17, 2023

This looks like a bug on the Kotlin side?

When list of fields is fetched in
com.squareup.anvil.compiler.codegen.dagger.DaggerGenerationUtils#declaredMemberInjectParameters, properties will list properties in the wrong order.

This only happens when base class is in another module and this = ClassReference.Descriptor. When class is in the same module, this = ClassReference.Psi the order is correct.

I would appreciate some help with reporting this upstream to Kotlin, since I'm not sure what exactly is happening behind the scenes to make a proper report.

By the way, I made a simple test for this issue here for even easier reproduce: matejdro@df9e78a

@matejdro matejdro changed the title Getting MembersInjector fails when both parent and subclass have Inject fields Getting MembersInjector's constructor has wront parameter order when base class with @Inject fields is in another module Jul 17, 2023
@matejdro matejdro changed the title Getting MembersInjector's constructor has wront parameter order when base class with @Inject fields is in another module MembersInjector's constructor has wront parameter order when base class with @Inject fields is in another module Jul 17, 2023
@matejdro matejdro changed the title MembersInjector's constructor has wront parameter order when base class with @Inject fields is in another module MembersInjector's constructor has wrong parameter order when base class with @Inject fields is in another module Jul 17, 2023
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

No branches or pull requests

1 participant