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

[Dagger/DuplicateBindings] if component's dependencies extends two or more interfaces with same method #1612

Closed
Tagakov opened this issue Sep 13, 2019 · 5 comments · Fixed by #1744
Assignees

Comments

@Tagakov
Copy link

Tagakov commented Sep 13, 2019

@Component(dependencies = Comp.Combined.class)
interface Comp {
    interface A {
        String s();
    }
    interface B {
        String s();
    }

    interface Combined extends A, B {
//        uncomment to make it compile
//        @Override
//        String s();
    }

    String s();
}

Error:

[Dagger/DuplicateBindings] java.lang.String is bound multiple times:
interface Comp {
^
      String com.example.playground.Comp.A.s()
      String com.example.playground.Comp.B.s()
      java.lang.String is provided at
          com.example.playground.Comp.s()

Looks like this issue is related to #472

Is it the intended behavior? At first glance, it looks like dagger shouldn't treat methods inherited from different interfaces as duplicate bindings if they have the same signature and qualifiers.

@nlgtuankiet
Copy link

What is the use case of this?

@Tagakov
Copy link
Author

Tagakov commented Sep 24, 2019

When interfaces A and B are quite big and you have to extend both it becomes hard to identify the intersection between them, also overridden methods doesn't bring any new information to the reader and bloats Combined interface with unrelated methods.

For example, we are using a hierarchy of @Components. Each @Component declares its own Dependencies which user should fulfill to instantiate that component. And in the case when one @Component A should be instantiated inside another @Component B component's B dependencies could extend the component's A dependencies.

@Component(dependencies = A.Dependencies.class)
interface A {
  interface Dependencies {
    //...
  }
}

@Component(dependencies = B.Dependencies.class)
interface B {
  interface Dependencies extends A.Dependencies, C.Dependencies, Etc.Dependencies {
    //...
  }
}

@Tagakov
Copy link
Author

Tagakov commented Oct 3, 2019

ping?

@Neronse
Copy link

Neronse commented Jan 16, 2020

same problem, Is there a solution to that?

@Chang-Eric
Copy link
Member

Going to work on fixing this, though FWIW this is still going to be somewhat fragile for you since it depends on naming of the methods. So if those two interfaces that presumably live apart name the getters differently, things will break and there won't really be a good answer to fixing it besides making the names match or factoring out shared deps into a single interface.

kluever pushed a commit that referenced this issue Feb 17, 2020
…o interfaces with the same method.

Fixes #1612.

RELNOTES=Fixed #1612

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=294775232
kluever pushed a commit that referenced this issue Feb 17, 2020
…o interfaces with the same method.

Fixes #1612.

RELNOTES=Fixed #1612

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=294775232
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.

4 participants