-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Dagger generates code with wrong parameter names and fails to compile #3401
Comments
@kozaxinan thanks for reporting this. I think this may be fixed at HEAD. Would it be possible for you to try using the HEAD-snapshot to verify? |
I checked new version but with snapshot, our build throws new exception during build before coming to original issue.
|
Hmm, that sounds like version skew between the different artifacts, e.g. maybe the If you haven't already, you should add the configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.google.dagger') {
details.useVersion "HEAD-SNAPSHOT"
}
}
} |
Okay, my mistake. I run the build with Snapshot. I couldn't reproduce the issue. But now I cannot reproduce the issue with old version as well. Is there a way to trigger this error more often to reproduce and test? |
It may be related to incremental processing, e.g. you can try first doing a clean build then changing something on the |
I'm having the same issue after updating from 2.27 to 2.42. Clean build does not help. |
Exactly like in the comment above, changing argument name in the component's method to arg0 has helped. |
@uKL can you try out the Dagger |
I was able to reproduce this on accident while switching to a new machine. I had the wrong asdf shim set and did an initial build with java 17 and switched back to java 11 and had this error. I was able to get rid of the error, by nuking the ~/.gradle dir and doing a fresh build, but I'm sure that was overkill and someone could just remove the incremental builds to get it working. |
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. |
@bcorso I tried the snapshot as well and still can reproduce the issue. Please let me know if there's anything else I could do. I ensured with the
|
@vRallev if you have time to put together a sample project with repro steps that would help a lot. I've been short on time lately, so it would make it a lot easier for me to narrow down the issue and verify the fix. |
The sample is here: https://github.com/vRallev/anvil/tree/ralf/dagger-bug Notice that the branch is
|
Thanks @vRallev! I'll make some time to look into it next week. |
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 @Singleton
@Component(modules = [ApplicationModule::class])
interface AppComponent {
@Component.Builder
interface Builder {
@BindsInstance
fun application(application: Application): Builder
fun build(): AppComponent
}
fun plusActivityComponent(activityModule: ActivityModule): ActivityComponent
...
}
TestComponent extends @Singleton
@Component(modules = [ApplicationModule::class])
interface TestComponent : AppComponent {
@Component.Builder
interface Builder {
@BindsInstance
fun application(application: Application): Builder
fun build(): TestComponent
}
...
} ActivityComponent a pretty standard subcomponent written in Kotlin @Subcomponent(modules = arrayOf(ActivityModule::class))
@ActivityScoped
interface ActivityComponent {
...
} Interestingly when I roll back to Dagger 2.41 the function is declared with a parameter name of @Override
public ActivityComponent plusActivityComponent(ActivityModule arg0) {
Preconditions.checkNotNull(arg0);
return new ActivityComponentImpl(testComponent, arg0);
} but in Dagger 2.42 the function parameter name is not replaced with @Override
public ActivityComponent plusActivityComponent(ActivityModule activityModule) {
Preconditions.checkNotNull(arg0);
return new ActivityComponentImpl(testComponentImpl, arg0);
} Interestingly, this suggests a workaround: |
Sorry, I was out last week. Just got some time to look into this and should have a fix submitted soon. |
Fixes #3401 This issue occurs when the original factory method is in a separate build unit from the component that implements it. This issue happens when building with Gradle (couldn't repro with Bazel) and when the original factory method is a kotlin library. This CL changes `createSubcomponentFactoryMethod()` to use the "overriding" factory method's parameters instead of the parameter names from the original factory method. RELNOTES=N/A PiperOrigin-RevId: 460473493
Awesome, thanks for the fix! |
A similar issue still happens for member injection. I filed a separate issue #3476. |
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;
Generated code;
Generated code has
module
parameter but code expectsarg0
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.
The text was updated successfully, but these errors were encountered: