dagger icon indicating copy to clipboard operation
dagger copied to clipboard

Use NameAllocator to avoid local/field name collisions.

Open christopherperry opened this issue 11 years ago • 1 comments

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();
    }

christopherperry avatar Mar 14 '14 01:03 christopherperry

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.

cgruber avatar Mar 14 '14 03:03 cgruber