Repository: square/anvil (kotlin)

Issue:
boundType does not appear to support Any
This piece of code:

```
@ContributesMultibinding(ActivityInjection::class, boundType = Any::class)
class TestViewModel @Inject constructor() : SimpleStackViewModel() {
...
}
```

Will throw an error:

```TestViewModel contributes a binding for kotlin.Any, but doesn't extend this type.```

Obviously, this class DOES extend Any.

This worked in Anvil 2.3.4 but it's now broken in 2.4.1.

Setting bound type to the `SimpleStackViewModel` works, so it appears just using `Any` as a boundType is an issue.

Pull request:
Fixes #619

Patch:
diff --git a/compiler/src/main/java/com/squareup/anvil/compiler/Utils.kt b/compiler/src/main/java/com/squareup/anvil/compiler/Utils.kt
index ad9e353c0..bf052f468 100644
--- a/compiler/src/main/java/com/squareup/anvil/compiler/Utils.kt
+++ b/compiler/src/main/java/com/squareup/anvil/compiler/Utils.kt
@@ -56,6 +56,7 @@ internal val assistedInjectFqName = AssistedInject::class.fqName
 internal val providerFqName = Provider::class.fqName
 internal val jvmSuppressWildcardsFqName = JvmSuppressWildcards::class.fqName
 internal val publishedApiFqName = PublishedApi::class.fqName
+internal val anyFqName = Any::class.fqName
 
 internal val daggerDoubleCheckFqNameString = DoubleCheck::class.java.canonicalName
 
diff --git a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/ClassReferenceExtensions.kt b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/ClassReferenceExtensions.kt
index 6f86748cd..4744f7b6e 100644
--- a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/ClassReferenceExtensions.kt
+++ b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/ClassReferenceExtensions.kt
@@ -1,5 +1,6 @@
 package com.squareup.anvil.compiler.codegen
 
+import com.squareup.anvil.compiler.anyFqName
 import com.squareup.anvil.compiler.assistedInjectFqName
 import com.squareup.anvil.compiler.contributesMultibindingFqName
 import com.squareup.anvil.compiler.injectFqName
@@ -81,6 +82,10 @@ internal fun ClassReference.checkClassExtendsBoundType(
       classReference = this
     )
 
+  // The boundType is declared explicitly in the annotation. Since all classes extend Any, we can
+  // stop here.
+  if (boundType.fqName == anyFqName) return
+
   if (allSuperTypeClassReferences().none { it.fqName == boundType.fqName }) {
     throw AnvilCompilationExceptionClassReference(
       message = "${this.fqName} contributes a binding for ${boundType.fqName}, but doesn't " +


Test patch:
diff --git a/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ContributesBindingGeneratorTest.kt b/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ContributesBindingGeneratorTest.kt
index 6979b6c60..665a258c9 100644
--- a/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ContributesBindingGeneratorTest.kt
+++ b/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ContributesBindingGeneratorTest.kt
@@ -309,6 +309,22 @@ class ContributesBindingGeneratorTest {
     }
   }
 
+  @Test fun `the contributed binding class can extend Any explicitly`() {
+    compile(
+      """
+      package com.squareup.test
+
+      import com.squareup.anvil.annotations.ContributesBinding
+
+      @ContributesBinding(Int::class, boundType = Any::class)
+      interface ContributingInterface
+      """
+    ) {
+      assertThat(contributingInterface.hintBinding?.java).isEqualTo(contributingInterface)
+      assertThat(contributingInterface.hintBindingScope).isEqualTo(Int::class)
+    }
+  }
+
   @Test fun `there are multiple hints for multiple contributed bindings`() {
     assumeIrBackend()
 
diff --git a/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ContributesMultibindingGeneratorTest.kt b/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ContributesMultibindingGeneratorTest.kt
index b80e82a74..b7ff4011c 100644
--- a/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ContributesMultibindingGeneratorTest.kt
+++ b/compiler/src/test/java/com/squareup/anvil/compiler/codegen/ContributesMultibindingGeneratorTest.kt
@@ -317,6 +317,22 @@ class ContributesMultibindingGeneratorTest {
     }
   }
 
+  @Test fun `the contributed multibinding class can extend Any explicitly`() {
+    compile(
+      """
+      package com.squareup.test
+
+      import com.squareup.anvil.annotations.ContributesMultibinding
+
+      @ContributesMultibinding(Int::class, boundType = Any::class)
+      interface ContributingInterface
+      """
+    ) {
+      assertThat(contributingInterface.hintMultibinding?.java).isEqualTo(contributingInterface)
+      assertThat(contributingInterface.hintMultibindingScope).isEqualTo(Int::class)
+    }
+  }
+
   @Test fun `a contributed multibinding can be generated`() {
     val codeGenerator = simpleCodeGenerator { clazz ->
       clazz