dagger: Dagger generates code with wrong parameter names and fails to compile
We recently updated Dagger from 2.37 to 2.42. Dagger time to time generates not compiling code. We have a component that uses other component.
Our simplified component;
@Subcomponent
interface ParentComponent {
fun inject(foo: Foo)
fun plus(module: FooModule): FooComponent
}
Generated code;
@Override
public FooComponent plus(FooModule module) {
Preconditions.checkNotNull(arg0);
return new FooComponentImpl(applicationComponentImpl, parentComponentImp, arg0);
}
Generated code has module
parameter but code expects arg0
name. This fails to compile.
If i change something in generated code and compile again, old generated code invalided and dagger generate correct code. But issue appears again, I couldnt find a common use case.
As workaround we changed module parameter name in ParentComponent to arg0 and it seems to prevents the issue up until now.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18
Sorry, I was out last week.
Just got some time to look into this and should have a fix submitted soon.
Seeing this as well, but interestingly, only in a test component that inherits from another component;
Our (simplified) usage in an Android app looks something like this:
Application component pretty standard android here; written in Kotlin
TestComponent extends
AppComponent
for use in some connected android tests and is written in KotlinActivityComponent a pretty standard subcomponent written in Kotlin
Interestingly when I roll back to Dagger 2.41 the function is declared with a parameter name of
arg0
inDaggerTestComponent
:but in Dagger 2.42 the function parameter name is not replaced with
arg0
, but it’s uses remainarg0
.Interestingly, this suggests a workaround: Anytime you’re doing something like this with a module, just name it
arg0
🤷♀️I’m having the same issue after updating from 2.40.1 to 2.42. I’ve noticed the problem occurs in multi-module project with components from non-main modules.
Using HEAD-SNAPSHOT artifacts causes multiple other issues with dagger modules from non-main modules.
Version 2.41 does not have this issue.
Kotlin version 1.6.21/1.6.10.
Exactly like in the comment above, changing argument name in the component’s method to arg0 has helped.