Skip to content

Commit

Permalink
fix bug where optimizer assumed references to existing provides were …
Browse files Browse the repository at this point in the history
…always properties

Fixes #321
  • Loading branch information
evant committed Nov 27, 2023
1 parent 16bc1bc commit cac1373
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,22 @@ abstract class ProvidesInnerClassComponent {
abstract val fooFactory: DifferentPackageFoo.Factory
}

// https://github.com/evant/kotlin-inject/issues/321
@Component
abstract class OptimizesProvides {
@Provides
fun OFooImpl.bind(): OFoo = this
abstract fun provideFoo(): OFoo
abstract fun provideBar(): OBar
}

interface OFoo
@Inject
class OFooImpl : OFoo

@Inject
class OBar(val foo: OFoo)

class ProvidesTest {

@Test
Expand Down Expand Up @@ -307,4 +323,12 @@ class ProvidesTest {

assertThat(component.fooFactory).isNotNull()
}

@Test
fun generates_a_component_where_a_provides_fun_optimizes_to_references_another_provides_fun() {
val component = OptimizesProvides::class.create()

assertThat(component.provideFoo()).isNotNull()
assertThat(component.provideBar()).isNotNull()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fun List<TypeResult.Provider>.optimize(context: Context): List<TypeResult.Provid
val newResult = TypeResult.Provides(
className = context.className,
methodName = name,
isProperty = true,
isProperty = provider?.isProperty ?: true,
)
if (provider == null) {
provider = TypeResult.Provider(
Expand Down

0 comments on commit cac1373

Please sign in to comment.