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

Cycle resolution fails depending on the ordering of items in the component

Open matejdro opened this issue 11 months ago • 1 comments

Attempting to compile following code:

@Component
abstract class AppComponent {
    abstract val items: Set<Base>

    @IntoSet
    @Provides
    fun provideFirstItem(firstItem: FirstItem): Base {
        return firstItem
    }

    @IntoSet
    @Provides
    fun provideSecondItem(secondItem: SecondItem): Base {
        return secondItem
    }
}

interface Base

class SetContainer @Inject constructor(objects: Set<Base>)

class FirstItem @Inject constructor(setContainer: Lazy<SetContainer>) : Base

class SecondItem @Inject constructor() : Base

will fail with Unresolved reference 'base'. error.

Interestingly enough, when swapping the order of provideFirstItem and provideSecondItem methods, this problem is fixed:

@Component
abstract class AppComponent {
    abstract val items: Set<Base>

    @IntoSet
    @Provides
    fun provideSecondItem(secondItem: SecondItem): Base {
        return secondItem
    }

    @IntoSet
    @Provides
    fun provideFirstItem(firstItem: FirstItem): Base {
        return firstItem
    }
}

interface Base

class SetContainer @Inject constructor(objects: Set<Base>)

class FirstItem @Inject constructor(setContainer: Lazy<SetContainer>) : Base

class SecondItem @Inject constructor() : Base

I don't think ordering of the methods inside component should matter at all. This is a pretty weird bug.

matejdro avatar Jan 10 '25 08:01 matejdro

Similar to #425?

matejdro avatar Jan 10 '25 08:01 matejdro