i'm debugging an issue with a pretty complex app t...
# kotlin-inject
d
i'm debugging an issue with a pretty complex app that i've been migrating from dagger to ki and i'm wondering if there's some obvious thing i'm missing here:
the generated class for one of my components has this code:
Copy code
override val loginManager: LoginManager
  get() = run<LoginManager> {
    lateinit var loginManager: LoginManager
    loginManager.also {
      loginManager = it
    }
  }
the component looks something like
Copy code
@Component
@ACustomScope
abstract class SomeComponent : SomeInterface {
    ...
    abstract val loginManager: LoginManager
    ...
}
and LoginManager:
Copy code
@ACustomScope
@Inject
class LoginManager(
    ... a bunch of parameters, all provided in SomeInterface or injected themselves ...
)
that generated code is clearly wrong with that lateinit var never being initialized
i'm trying to reproduce this in a small demo project but without success so far, but is there some obvious combination of factors that could cause that code to be generated?
e
Yeah seems like a bug but I don't know an obvious combination that would cause it. Please put as much info you can in a bug report!
Late init implies a circular dependency if that helps
d
got it:
Copy code
import me.tatarka.inject.annotations.Component
import me.tatarka.inject.annotations.Inject
import me.tatarka.inject.annotations.Scope

@Scope
annotation class CustomScope

@CustomScope
@Component
abstract class BaseComponent {
    abstract val foo: Foo
    abstract val bar: Bar
}

@CustomScope
@Inject
class Foo(
    val lazy: Lazy<Bar>,
    val real: Bar,
)

@Inject
class Bar(
    val foo: Lazy<Foo>
)
generates
Copy code
import kotlin.reflect.KClass
import me.tatarka.inject.`internal`.LazyMap
import me.tatarka.inject.`internal`.ScopedComponent

public fun KClass<BaseComponent>.create(): BaseComponent = InjectBaseComponent()

public class InjectBaseComponent() : BaseComponent(), ScopedComponent {
  override val _scoped: LazyMap = LazyMap()

  override val foo: Foo
    get() = run<Foo> {
      lateinit var foo: Foo
      foo.also {
        foo = it
      }
    }

  override val bar: Bar
    get() = Bar(
      foo = lazy {
        foo
      }
    )
}
i'll file a bug
👍 1