dagger
dagger copied to clipboard
Use NameAllocator to avoid local/field name collisions.
The following causes Dagger to compile incorrectly.
@Module(
injects = SomeClass.class
)
public static class MyModule {
@Provides InjectedClass provideInjectedClass() {
return new InjectedClass();
}
}
public static class SomeClass {
@Inject InjectedClass object; // Problem is with variable name
}
public static class InjectedClass {}
@Test
public void dagger_shouldInject() {
ObjectGraph objectGraph = ObjectGraph.create(new MyModule());
SomeClass someClass = new SomeClass();
objectGraph.inject(someClass);
assertThat(someClass.object).isNotNull();
}
Hah. I think you caught a corner case we were just discussing in the Dagger 2 initial work. We should definitely fix this in the 1.x branch though.