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

Strange behavior: @Binds methods' parameter type must be assignable to the return type. #885

Open
SteinerOk opened this issue Feb 24, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@SteinerOk
Copy link

SteinerOk commented Feb 24, 2024

First of all, I want to say that I have read this fix (#833) and understand the situation described below.

I have a set of custom code generators, before version 2.5.0-beta02 they ran fine and were used in a working project, but after updating to 2.5.0-beta02 I get a compilation error:

e: com.squareup.anvil.compiler.api.AnvilCompilationException: Back-end (JVM) Internal error: @Binds methods' parameter type must be assignable to the return type. Expected binding of type dev.steinerok.sealant.work.WorkerAssistedFactory<out androidx.work.ListenableWorker> but impl parameter of type dev.steinerok.sealant.sample.feature.home.FeatureHomeWorker_AssistedFactory only has the following supertypes: [dev.steinerok.sealant.work.WorkerAssistedFactory<dev.steinerok.sealant.sample.feature.home.FeatureHomeWorker>]
File being compiled: (36,3) in //Users/steinerok/Documents/Projects/sealant/sample/feature-home/build/anvil/debug/generated/dev/steinerok/sealant/sample/feature/home/FeatureHomeWorker_Creation.kt

	at com.squareup.anvil.compiler.internal.reference.FunctionReferenceKt.AnvilCompilationExceptionFunctionReference(FunctionReference.kt:45)
	at com.squareup.anvil.compiler.internal.reference.FunctionReferenceKt.AnvilCompilationExceptionFunctionReference$default(FunctionReference.kt:40)
	at com.squareup.anvil.compiler.codegen.dagger.BindsMethodValidator.validateBindsFunction(BindsMethodValidator.kt:117)
	at com.squareup.anvil.compiler.codegen.dagger.BindsMethodValidator.checkCode(BindsMethodValidator.kt:72)
	at com.squareup.anvil.compiler.codegen.CheckOnlyCodeGenerator.generateCodePrivate(CheckOnlyCodeGenerator.kt:18)
	at com.squareup.anvil.compiler.codegen.PrivateCodeGenerator.generateCode(PrivateCodeGenerator.kt:20)
	at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.generateCode$generateCode(CodeGenerationExtension.kt:198)
	at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.generateCode(CodeGenerationExtension.kt:236)
	at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.analysisCompleted(CodeGenerationExtension.kt:127)

BUT the point is that it only occurs when you use:

anvil {
    generateDaggerFactories.set(true)
}

If I don't use Anvil generateDaggerFactories, but use KAPT instead, everything compiles fine.

It seems to me that the behavior should be the same in both cases?

To reproduse repo: https://github.com/SteinerOk/sealant/tree/ik/sample
Compile fine: assembleDebug in :sample:feature-home-kapt
Compile error: assembleDebug in :sample:feature-home

@RBusarow
Copy link
Member

Thanks for the report!

There was a change to how we validate binding parameters, and the new logic isn't handling generics properly. I'll get a fix out today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants