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

Conflicting imports are sometimes generated in Anvil 2.4.6+ #738

Closed
JoelWilcox opened this issue Aug 2, 2023 · 0 comments · Fixed by #739
Closed

Conflicting imports are sometimes generated in Anvil 2.4.6+ #738

JoelWilcox opened this issue Aug 2, 2023 · 0 comments · Fixed by #739
Assignees
Labels
bug Something isn't working

Comments

@JoelWilcox
Copy link
Member

Use case: When there is a simple name conflict between two imports and one of them is an inner class, the resulting alias that gets created for the inner class can conflict with other imports. So far the following snippet is the smallest reproducible use-case that mimics the sort of setup we noticed this issue in for assisted factories.

      package com.squareup.test
      
      import javax.inject.Inject
      
      class InjectClass @Inject constructor() {
        interface Factory {
          fun doSomething()
        }
      }

      class InjectClassFactory @Inject constructor(val factory: InjectClass.Factory)

We started seeing this issue in Anvil 2.4.6 after upgrading to KotlinPoet 1.13.0. I filed square/kotlinpoet#1648 but it turns out this is a long-standing bug in Anvil that only coincidentally worked with previous versions of KotlinPoet. The bug is that when we convert FqNames to ClassNames, there are some situations like the one above where we incorrectly identify which parts of a fully qualified name are the package and which are simple names (e.g. in the case of a nested class). In the above code, this would result in us creating a ClassName(package = "com.squareup.test.InjectClass", simpleNames = listOf("Factory")) when it should be ClassName(package = "com.squareup.test", simpleNames = listOf("InjectClass", "Factory")

@JoelWilcox JoelWilcox added the bug Something isn't working label Aug 2, 2023
@JoelWilcox JoelWilcox self-assigned this Aug 2, 2023
JoelWilcox added a commit that referenced this issue Aug 2, 2023
…e, which would result in conflicting generated imports

Fixes #738.
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

Successfully merging a pull request may close this issue.

1 participant