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

Regression in 2.3.7 with generic assisted factories #395

Closed
ZacSweers opened this issue Oct 20, 2021 · 2 comments · Fixed by #396
Closed

Regression in 2.3.7 with generic assisted factories #395

ZacSweers opened this issue Oct 20, 2021 · 2 comments · Fixed by #396
Labels
bug Something isn't working dagger factory Happens when generateDaggerFactories is set to true

Comments

@ZacSweers
Copy link
Collaborator

we have a base interface for our factories that looks like this

interface AssistedWorkerFactory<T : ListenableWorker> {
  fun create(context: Context, params: WorkerParameters): T
}

with 2.3.7, this now results in this compilation exception

e: com.squareup.anvil.compiler.api.AnvilCompilationException: Back-end (JVM) Internal error: Invalid return type: slack.workmanager.workerfactory.AssistedWorkerFactory.create. An assisted factory's abstract method must return a type with an @AssistedInject-annotated constructor.
File being compiled: (17,3) in /mnt/buildkite-agent/builds/mbr-buildkite-agent-android-iad-ju4p-1/slack/android-pull-request/services/work-manager/src/main/kotlin/slack/workmanager/workerfactory/AssistedWorkerFactory.kt
 
	at com.squareup.anvil.compiler.codegen.dagger.AssistedFactoryGenerator$AssistedFactoryFunction$Companion$toAssistedFactoryFunction$returnTypeLazy$2.invoke(AssistedFactoryGenerator.kt:313)

I think this is an issue with it not properly reading the generic type. As an example, this is what we are doing

class FlushPendingExposuresWork @AssistedInject constructor(
  @Assisted appContext: Context,
  @Assisted params: WorkerParameters,
  // ...
) : CoroutineWorker(appContext, params) {

  override suspend fun doWork(): Result {
    // ...
  }

  @AssistedFactory
  interface Factory : AssistedWorkerFactory<FlushPendingExposuresWork>
}
@vRallev vRallev added bug Something isn't working dagger factory Happens when generateDaggerFactories is set to true labels Oct 20, 2021
@RBusarow
Copy link
Collaborator

🤦

Thanks for the report, and sorry for the bug. I'll look into it now.

The fun part is that by supporting PSI, there are now two scenarios where it can fail.

@vRallev
Copy link
Collaborator

vRallev commented Oct 20, 2021

Thanks @RBusarow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dagger factory Happens when generateDaggerFactories is set to true
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants