Skip to content

Unhelpful compilation error message in case of a wrongful usage of @AssistedInject #5071

@aviv-nino

Description

@aviv-nino

Running this code:

@Component(dependencies = [FooDependencies::class])
interface FooComponent {

    fun getFooFactory(): FooFactory

    @Component.Builder
    interface Builder {
        fun dependencies(dependencies: FooDependencies): Builder
        fun build(): FooComponent
    }

    @AssistedFactory
    interface FooFactory {
        fun create(
            @Assisted(KEY_FOO) foo: Boolean,
        ): Foo

        companion object {
            internal const val KEY_FOO = "KEY_FOO"
        }
    }
}

// 👇 Notice the @Inject instead of @AssistedInject
class Foo @Inject constructor(
    @Assisted(KEY_FOO) private val foo: Boolean,
)

will result in a simple e: [ksp] java.lang.IllegalArgumentException compilation error.

A better error would be helpful, as it is quite common to switch to an @AssistedInject strategy and forget about the constructor annotation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions