Repository: square/anvil
Issue: Incorrectly getting error: There are multiple contributed bindings with the same bound type

Hi folks I'm getting pretty certain that there is a bug in  the version of anvil that brought in contributes subcomponent. I first saw it in sample app and now in our main app when integrating our anvil wrapping library. Generally what happens is I run the application and everything is fine, next I make a change. I rerun through android studio and I get a duplicate binding for a random class. Always a class that is a ContributesBinding and always a class that is in a file different than the class name. In my sample I moved all contributes bindings to their own file and the error has not happened since. 

This is the trace. I've been a bit overwhelmed with life/baby and unable to make a sample for you but just wanted to let you know its still happening, its happened 5 times to me this am. Doing a clean  fixes it every time. We are on kotlin 1.5.31. It surprises me no one else has hit/is reporting the same. I don't believe my setup is atypical
```
com.squareup.anvil.compiler.api.AnvilCompilationException: Back-end (JVM) Internal error: There are multiple contributed bindings with the same bound type. The bound type is com.dropbox.common.feature_gating.`annotation`.FeatureGatingRegistrar. The contributed binding classes are: [com.dropbox.skeleton_sandbox.app.RealNoAuthFeatureGatingRegistry, com.dropbox.skeleton_sandbox.app.RealNoAuthFeatureGatingRegistry]
File is unknown

	at com.squareup.anvil.compiler.codegen.BindingModuleGeneratorKt.findHighestPriorityBinding(BindingModuleGenerator.kt:375)
	at com.squareup.anvil.compiler.codegen.BindingModuleGeneratorKt.access$findHighestPriorityBinding(BindingModuleGenerator.kt:1)
	at com.squareup.anvil.compiler.codegen.BindingModuleGenerator.flush$lambda-13$getContributedBindingClasses(BindingModuleGenerator.kt:248)
	at com.squareup.anvil.compiler.codegen.BindingModuleGenerator.flush(BindingModuleGenerator.kt:256)
	at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.analysisCompleted$flush(CodeGenerationExtension.kt:99)
	at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.analysisCompleted(CodeGenerationExtension.kt:110)
```

The first time I hit this issue was in github.com/dropbox/kaiken the next time was while integrating the newest version of Kaiken into our internal code base. I'm not sure if Kaiken has something that is an atypical config, the only thing I can think of is we have a code generator that plugs into Anvil

Changed files:
compiler/src/main/java/com/squareup/anvil/compiler/codegen/BindingModuleGenerator.kt

diff --git a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/BindingModuleGenerator.kt b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/BindingModuleGenerator.kt
index a023731..7a0702d 100644
--- a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/BindingModuleGenerator.kt
+++ b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/BindingModuleGenerator.kt
@@ -370,6 +370,9 @@ private fun List<ContributedBinding>.findHighestPriorityBinding(): ContributedBi
   val bindings = groupBy { it.priority }
     .toSortedMap()
     .let { it.getValue(it.lastKey()) }
+    // In some very rare cases we can see a binding for the same type twice. Just in case filter
+    // them, see https://github.com/square/anvil/issues/460.
+    .distinctBy { it.contributedFqName }
 
   if (bindings.size > 1) {
     throw AnvilCompilationException(