google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.41k stars 2.01k forks source link

Dagger generates subcomponent builder with name same as builder interface name #822

Open guliash opened 7 years ago

guliash commented 7 years ago
@Component
public interface MyComponent {

    MySubcomponent.MySubcomponentBuilder mySubcomponentBuider();

}
@Subcomponent
public interface MySubcomponent {

    @Subcomponent.Builder
    interface MySubcomponentBuilder {

        @BindsInstance
        MySubcomponentBuilder integer(Integer integer);

        MySubcomponent build();

    }

    void inject(B b);
}
public class A {

    @Inject
    public A(Integer integer) {

    }

}
public class B {

    @Inject
    A a;

}
public class Main {

    public static void main(String[] args) {
        DaggerMyComponent.create().mySubcomponentBuider().integer(42).build().inject(new B());
    }

}

This code produces next error:

error: cannot find symbol this.integerProvider = InstanceFactory.create(builder.integer);

Because it tries to get integer from the builder interface, not the implementation.

Code here

ronshapiro commented 6 years ago

Ah, this is definitely a good edge case. We should fix this (though probably low priority)