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

ContributesSubcomponent.Factory validation fails when the function is overridden #1044

Open
jonamireh opened this issue Jul 30, 2024 · 0 comments · May be fixed by #1070
Open

ContributesSubcomponent.Factory validation fails when the function is overridden #1044

jonamireh opened this issue Jul 30, 2024 · 0 comments · May be fixed by #1070

Comments

@jonamireh
Copy link

jonamireh commented Jul 30, 2024

It appears that after #1042, overridden abstract functions are being miscounted in regards to subcomponent factory interfaces, despite being the same function. Consider the following configuration:

//Example.kt
package com.squareup.test

import com.squareup.anvil.annotations.ContributesSubcomponent

@ContributesSubcomponent(Any::class, parentScope = Unit::class)
interface SubcomponentInterface : BaseSubcomponent {
  @ContributesSubcomponent.Factory
  interface Factory : BaseSubcomponent.Factory {
    override fun create(@BindsInstance provided: String): SubcomponentInterface
  }

  @ContributesTo(Unit::class)
  interface ParentComponent {
      fun createSubcomponentFactory(): SubcomponentInterface.Factory
  }
}

interface BaseSubcomponent {
  interface Factory {
    fun create(provided: String): BaseSubcomponent
  }
}

This works as expected on 2.5.0-beta09 but if you try to compile this on 2.5.0-beta10, you get:

e: com.squareup.anvil.compiler.api.AnvilCompilationException: Back-end (JVM) Internal error: A factory must have exactly one abstract function returning the subcomponent com.squareup.test.SubcomponentInterface
File being compiled: (09,12) in Example.kt

        at com.squareup.anvil.compiler.internal.reference.ClassReferenceKt.AnvilCompilationExceptionClassReference(ClassReference.kt:553)
        at com.squareup.anvil.compiler.internal.reference.ClassReferenceKt.AnvilCompilationExceptionClassReference$default(ClassReference.kt:548)
        at com.squareup.anvil.compiler.codegen.ContributesSubcomponentCodeGen$Embedded.checkFactory(ContributesSubcomponentCodeGen.kt:390)
        at com.squareup.anvil.compiler.codegen.ContributesSubcomponentCodeGen$Embedded.access$checkFactory(ContributesSubcomponentCodeGen.kt:244)
        at com.squareup.anvil.compiler.codegen.ContributesSubcomponentCodeGen$Embedded$generateCode$3.invoke(ContributesSubcomponentCodeGen.kt:285)
        at com.squareup.anvil.compiler.codegen.ContributesSubcomponentCodeGen$Embedded$generateCode$3.invoke(ContributesSubcomponentCodeGen.kt:284)
        at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210)
        at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:811)
        at com.squareup.anvil.compiler.codegen.ContributesSubcomponentCodeGen$Embedded.generateCode(ContributesSubcomponentCodeGen.kt:303)
        at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.generateCode$generateAndCache(CodeGenerationExtension.kt:229)
        at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.generateCode$loopGeneration(CodeGenerationExtension.kt:255)
        at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.generateCode(CodeGenerationExtension.kt:266)
        at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.analysisCompleted(CodeGenerationExtension.kt:121)

@jonamireh jonamireh changed the title ContributesSubcomponent.Factory validation fails when the function is inherited and overridden ContributesSubcomponent.Factory validation fails when the function is overridden Jul 30, 2024
@esafirm esafirm linked a pull request Nov 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant