kotlin-inject icon indicating copy to clipboard operation
kotlin-inject copied to clipboard

Bug in code generation for `@AssistedFactory`

Open sproctor opened this issue 7 months ago • 2 comments

I started to migrate a few lambda factories to interfaces and got Unresolved reference '_scoped'. It appears that components are not always cast to ScopedComponent when _scoped is accessed.

sproctor avatar Apr 28 '25 20:04 sproctor

Thanks for the report, if you can share a component graph that reproduces the issue that'd help a lot

evant avatar Apr 28 '25 22:04 evant

I have the same issue. My DI graph

I have Singleton scope

@Scope
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER)
annotation class Singleton

Have KmpComponent

@Singleton
@Component
abstract class KmpComponent {

    @Provides
    @Singleton
    fun dependencyA(): A = AImpl()
}

interface A

class AImpl : A

Have DecomposeFactoryComponent

@Component
abstract class DecomposeFactoryComponent(parent: KmpComponent) {

    abstract val factory: CreateFactory
}

@Inject
class B(@Assisted assisted: Boolean, a: A)

@AssistedFactory
interface CreateFactory {
    fun create(
        assisted: Boolean
    ): B
}

When run app got such error:

Argument type mismatch: actual type is 'MatchGroup?', but 'A' was expected.

Image

YuryPashkov avatar Jun 10 '25 07:06 YuryPashkov