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

[AssistedInject] Dagger generates code that calls an infinite loop #2359

Closed
efemoney opened this issue Feb 5, 2021 · 1 comment · Fixed by #2362
Closed

[AssistedInject] Dagger generates code that calls an infinite loop #2359

efemoney opened this issue Feb 5, 2021 · 1 comment · Fixed by #2362

Comments

@efemoney
Copy link

efemoney commented Feb 5, 2021

Using Dagger 2.31.2 with fastInit enabled, I am seeing that Dagger generates a Component/Subcomponent that returns the AssitedInject.Factory as an anonymous object. When the factory method name, however, is the same as the AssistedInject classname in camelCase, then the Anonymous factory implementation tries to call itself as shown in the screenshots below.

generated component:
image

assisted inject definition:
image

The 'workaround' is to name the factory method create or something else (like most normal people would do 🙈)

@bcorso
Copy link

bcorso commented Feb 5, 2021

Thanks for reporting this!

@bcorso bcorso self-assigned this Feb 5, 2021
copybara-service bot pushed a commit that referenced this issue Feb 6, 2021
…method calls a generated component method with the same name.

The problem exists in FastInit mode, where the private method name can conflict with the factory method name:

```
final class DaggerMyComponent implements MyComponent {
  @OverRide
  public FooFactory fooFactory() {
    return new FooFactory() {
      @OverRide
      public Foo foo() {
        return foo();  // This calls factory method rather than component method
      }
    };
  }

  private Foo foo() {
    return new Foo(getDep());
  }
}
```

The fix is to reference outer component when calling the private method within the anonymous class.

Fixes #2359

RELNOTES=Fixes #2359: Fixes self-loop when generated implementation of an assisted factory method calls a generated component method with the same name.
PiperOrigin-RevId: 355887899
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants