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

ContributesSubcomponent.Factory validation fails when the function is inherited and returns a generic #1041

Closed
RBusarow opened this issue Jul 26, 2024 · 0 comments · Fixed by #1042
Assignees
Labels
bug Something isn't working

Comments

@RBusarow
Copy link
Collaborator

There are a number of places in Subcomponent factory validation where Anvil hasn't been resolving the generic return types of the factory function. For example, in the following snippet, create() returns SubcomponentInterface but it's only treated as the T type variable.

package com.squareup.test

import com.squareup.anvil.annotations.ContributesSubcomponent

@ContributesSubcomponent(Any::class, parentScope = Unit::class)
interface SubcomponentInterface {
  @ContributesSubcomponent.Factory
  interface ComponentFactory : GenericFactory<SubcomponentInterface>
}

interface GenericFactory<T> {
  fun create(): T
}

example exception:

Compilation failed unexpectedly

e: com.squareup.anvil.compiler.api.AnvilCompilationException: Back-end (JVM) Internal error: Unable to resolve type for T.
File is unknown

	at com.squareup.anvil.compiler.internal.DescriptorUtilsKt.classDescriptor(DescriptorUtils.kt:32)
	at com.squareup.anvil.compiler.internal.reference.TypeReferenceKt.AnvilCompilationExceptionTypReference(TypeReference.kt:503)
	at com.squareup.anvil.compiler.internal.reference.TypeReferenceKt.AnvilCompilationExceptionTypReference$default(TypeReference.kt:491)
	at com.squareup.anvil.compiler.internal.reference.TypeReference.asClassReference(TypeReference.kt:75)
	at com.squareup.anvil.compiler.codegen.ContributesSubcomponentCodeGen$Embedded.checkParentComponentInterface(ContributesSubcomponentCodeGen.kt:328)
	at com.squareup.anvil.compiler.codegen.ContributesSubcomponentCodeGen$Embedded.access$checkParentComponentInterface(ContributesSubcomponentCodeGen.kt:244)
        [...]
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