Repository: square/anvil (kotlin)

Issue:
`Provider<Lazy<Type>>` not handled properly for member injection
Given this:

```kotlin
class InjectClass {
  @Inject lateinit var lazyStringProvider: Provider<Lazy<String>>
}
```

This is generated:
```kotlin
public class InjectClass_MembersInjector(
  private val param0: Provider<@JvmSuppressWildcards String>
) : MembersInjector<InjectClass> {
  public override fun injectMembers(instance: InjectClass): Unit {
    injectLazyStringProvider(instance, param0)  // attempting to pass a Provider<String> instead of Provider<Lazy<String>>
  }

  public companion object {
    @JvmStatic
    public fun create(param0: Provider<@JvmSuppressWildcards String>): InjectClass_MembersInjector =
        InjectClass_MembersInjector(param0)

    @JvmStatic
    @InjectedFieldSignature("com.squareup.test.InjectClass.lazyStringProvider")
    public fun injectLazyStringProvider(instance: InjectClass,
        lazyStringProvider: Provider<Lazy<@JvmSuppressWildcards String>>): Unit {
      instance.lazyStringProvider = lazyStringProvider
    }
  }
}

```

And what we want is this:
```kotlin
public class InjectClass_MembersInjector(
  private val param0: Provider<@JvmSuppressWildcards String>
) : MembersInjector<InjectClass> {
  public override fun injectMembers(instance: InjectClass): Unit {
    injectLazyStringProvider(instance, dagger.internal.ProviderOfLazy.create(param0))
  }

  public companion object {
    @JvmStatic
    public fun create(param0: Provider<@JvmSuppressWildcards String>): InjectClass_MembersInjector =
        InjectClass_MembersInjector(param0)

    @JvmStatic
    @InjectedFieldSignature("com.squareup.test.InjectClass.lazyStringProvider")
    public fun injectLazyStringProvider(instance: InjectClass,
        lazyStringProvider: Provider<Lazy<@JvmSuppressWildcards String>>): Unit {
      instance.lazyStringProvider = lazyStringProvider
    }
  }
}
```

Pull request:
fixes #365

Patch:
diff --git a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/MembersInjectorGenerator.kt b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/MembersInjectorGenerator.kt
index c62cfb0b2..b024e03a9 100644
--- a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/MembersInjectorGenerator.kt
+++ b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/MembersInjectorGenerator.kt
@@ -33,6 +33,7 @@ import com.squareup.kotlinpoet.asClassName
 import com.squareup.kotlinpoet.jvm.jvmStatic
 import dagger.MembersInjector
 import dagger.internal.InjectedFieldSignature
+import dagger.internal.ProviderOfLazy
 import org.jetbrains.kotlin.descriptors.ModuleDescriptor
 import org.jetbrains.kotlin.descriptors.PropertyDescriptor
 import org.jetbrains.kotlin.psi.KtClassOrObject
@@ -139,6 +140,8 @@ internal class MembersInjectorGenerator : PrivateCodeGenerator() {
                   val property = injectProperties[index]
 
                   val parameterString = when {
+                    parameter.isLazyWrappedInProvider ->
+                      "${ProviderOfLazy::class.qualifiedName}.create(${parameter.name})"
                     parameter.isWrappedInProvider -> parameter.name
                     parameter.isWrappedInLazy ->
                       "$daggerDoubleCheckFqNameString.lazy(${parameter.name})"


Test patch:
diff --git a/compiler/src/test/java/com/squareup/anvil/compiler/dagger/MembersInjectorGeneratorTest.kt b/compiler/src/test/java/com/squareup/anvil/compiler/dagger/MembersInjectorGeneratorTest.kt
index e862d8296..aa14aec3b 100644
--- a/compiler/src/test/java/com/squareup/anvil/compiler/dagger/MembersInjectorGeneratorTest.kt
+++ b/compiler/src/test/java/com/squareup/anvil/compiler/dagger/MembersInjectorGeneratorTest.kt
@@ -505,6 +505,94 @@ public final class InjectClass_MembersInjector implements MembersInjector<Inject
     }
   }
 
+  @Test fun `a factory class is generated for a field injection with Lazy wrapped in a Provider`() {
+    /*
+package com.squareup.test;
+
+import dagger.Lazy;
+import dagger.MembersInjector;
+import dagger.internal.DaggerGenerated;
+import dagger.internal.InjectedFieldSignature;
+import dagger.internal.ProviderOfLazy;
+import javax.annotation.processing.Generated;
+import javax.inject.Provider;
+
+@DaggerGenerated
+@Generated(
+    value = "dagger.internal.codegen.ComponentProcessor",
+    comments = "https://dagger.dev"
+)
+@SuppressWarnings({
+    "unchecked",
+    "rawtypes"
+})
+public final class InjectClass_MembersInjector implements MembersInjector<InjectClass> {
+  private final Provider<String> stringProvider;
+
+  public InjectClass_MembersInjector(Provider<String> stringProvider) {
+    this.stringProvider = stringProvider;
+  }
+
+  public static MembersInjector<InjectClass> create(Provider<String> stringProvider) {
+    return new InjectClass_MembersInjector(stringProvider);
+  }
+
+  @Override
+  public void injectMembers(InjectClass instance) {
+    injectLazyStringProvider(instance, ProviderOfLazy.create(stringProvider));
+  }
+
+  @InjectedFieldSignature("com.squareup.test.InjectClass.lazyStringProvider")
+  public static void injectLazyStringProvider(InjectClass instance,
+      Provider<Lazy<String>> lazyStringProvider) {
+    instance.lazyStringProvider = lazyStringProvider;
+  }
+}
+     */
+
+    compile(
+      """
+      package com.squareup.test
+      
+      import dagger.Lazy
+      import javax.inject.Inject
+      import javax.inject.Provider
+      
+      class InjectClass {
+        @Inject lateinit var lazyStringProvider: Provider<Lazy<String>>
+        
+        override fun equals(other: Any?): Boolean {
+          return toString() == other.toString()
+        }
+        override fun toString(): String {
+         return lazyStringProvider.get().get()
+        }
+      }
+      """
+    ) {
+      val membersInjector = injectClass.membersInjector()
+
+      val constructor = membersInjector.declaredConstructors.single()
+      assertThat(constructor.parameterTypes.toList())
+        .containsExactly(Provider::class.java)
+
+      val membersInjectorInstance = constructor
+        .newInstance(Provider { "a" })
+        as MembersInjector<Any>
+
+      val injectInstanceConstructor = injectClass.createInstance()
+      membersInjectorInstance.injectMembers(injectInstanceConstructor)
+
+      val injectInstanceStatic = injectClass.createInstance()
+
+      membersInjector.staticInjectMethod("lazyStringProvider")
+        .invoke(null, injectInstanceStatic, Provider { dagger.Lazy { "a" } })
+
+      assertThat(injectInstanceConstructor).isEqualTo(injectInstanceStatic)
+      assertThat(injectInstanceConstructor).isNotSameInstanceAs(injectInstanceStatic)
+    }
+  }
+
   @Test fun `a factory class is generated for a field injection with star imports`() {
     /*
 package com.squareup.test;