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

Anvil KSP processors don't support multi-round processing #1034

Open
jonamireh opened this issue Jul 17, 2024 · 0 comments
Open

Anvil KSP processors don't support multi-round processing #1034

jonamireh opened this issue Jul 17, 2024 · 0 comments

Comments

@jonamireh
Copy link

jonamireh commented Jul 17, 2024

It appears that the KSP processors that are enabled when useKsp(true, false) is invoked within the AnvilExtension do not support multi-round processing. In particular, if the module depends on another KSP processor that generates code that is meant to be consumed by Anvil, it won't be able to resolve that type. One example is we'll generate a type that is then member injected so when Anvil tries to generate the member injector for the enclosing class, we get:

e: [ksp] java.lang.IllegalArgumentException: Error type '<ERROR TYPE>' is not resolvable in the current round of processing.
        at com.squareup.kotlinpoet.ksp.KsTypesKt.toTypeName(KsTypes.kt:64)
        at com.squareup.kotlinpoet.ksp.KsTypesKt.toTypeName(KsTypes.kt:58)
        at com.squareup.anvil.compiler.codegen.dagger.DaggerGenerationUtilsKt.toMemberInjectParameter(DaggerGenerationUtils.kt:465)
        at com.squareup.anvil.compiler.codegen.dagger.DaggerGenerationUtilsKt.declaredMemberInjectParameters(DaggerGenerationUtils.kt:282)
        at com.squareup.anvil.compiler.codegen.dagger.DaggerGenerationUtilsKt.memberInjectParameters(DaggerGenerationUtils.kt:260)
        at com.squareup.anvil.compiler.codegen.dagger.MembersInjectorCodeGen$KspGenerator.processChecked(MembersInjectorCodeGen.kt:82)
        at com.squareup.anvil.compiler.codegen.ksp.AnvilSymbolProcessor.process(AnvilSymbolProcessing.kt:31)

I've supplied two patches: the first is for a very silly KSP processor that is configured in the way I've described above to reproduce this stacktrace (try running ./gradlew :delegate:sample:library:assemble) and the second is just naively applying the recommendations of the KSP documentation for multi-round processing by deferring invalid symbols within MemberInjectorCodeGen, although I would assume that this sort of change would need to be applied to each KSP processor within Anvil

0001-failing-project.patch
0002-Fix-MemberInjectorCodeGen.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant