Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kotlin-inject generates dead code #451

Open
vRallev opened this issue Oct 31, 2024 · 1 comment
Open

kotlin-inject generates dead code #451

vRallev opened this issue Oct 31, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@vRallev
Copy link
Contributor

vRallev commented Oct 31, 2024

This is one field being generated:

private val meteredCommunication: MeteredCommunication
  get() = _scoped.get("com.amazon.bivis.service.MeteredCommunication") {
    run<MeteredCommunication> {
      lateinit var meteredCommunication: MeteredCommunication
      provideMeteredCommunicationImpl(
        ...
      ).also {
        meteredCommunication = it
      }
    }
  }

Another example:

private val infoService: InfoService
  get() = run<InfoService> {
    lateinit var infoService: InfoService
    provideInfoServiceImplInfoService(
      infoServiceImpl = infoServiceImpl
    ).also {
      infoService = it
    }
  }

In both samples the lateinit var is redundant and not used. kotlin-inject should not generate dead code.

@evant evant added the bug Something isn't working label Oct 31, 2024
@evant
Copy link
Owner

evant commented Oct 31, 2024

Likely related to #449 because both contain lateinit which is used for breaking cycles. I might have mentioned this on another ticket but the cycle handling code is not great and needs to be re-written. You are also seeing more duplicate code using them as it was a quick fix against invalid code generation caused by trying to de-dup the common parts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants