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 doesn't support inherited functions #1003

Open
esafirm opened this issue May 14, 2024 · 0 comments
Open

ContributesSubcomponent.Factory doesn't support inherited functions #1003

esafirm opened this issue May 14, 2024 · 0 comments

Comments

@esafirm
Copy link

esafirm commented May 14, 2024

The document said that

This follows all the rules of Subcomponent.Factory, except it must appear in classes
annotated with @ContributesSubcomponent instead of @Subcomponent.

But ContributesSubcomponent.Factory actually doesn't support inherited function.

package com.squareup.test

import com.squareup.anvil.annotations.ContributesSubcomponent
import com.squareup.anvil.annotations.ContributesSubcomponent.Factory
import com.squareup.anvil.annotations.ContributesTo
import com.squareup.anvil.annotations.MergeComponent

@ContributesSubcomponent(Any::class, parentScope = Unit::class)
interface SubcomponentInterface {
    @ContributesTo(Unit::class)
    interface AnyParentComponent {
        fun createFactory(): ComponentFactory
    }

    interface Creator {
        fun createComponent(): SubcomponentInterface
    }

    @Factory
    abstract class ComponentFactory : Creator
}

@MergeComponent(Unit::class)
interface ComponentInterface

The code above will fail if we're using @ContributesSubcomponent.Factory but will pass for @Subcomponent.Factory

Another thing is, while I haven't tested it, the KSP part of the code gen might support the above code, since in here it use getAllFunctions that will returns declared and inherited functions.

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

No branches or pull requests

1 participant