Strange behavior: @Binds methods' parameter type must be assignable to the return type. #885
Open
Description
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