diff --git a/integration-tests/demo/src/main/kotlin/com/squareup/test/demo/DemoService.kt b/integration-tests/demo/src/main/kotlin/com/squareup/test/demo/DemoService.kt new file mode 100644 index 0000000..eafc02b --- /dev/null +++ b/integration-tests/demo/src/main/kotlin/com/squareup/test/demo/DemoService.kt @@ -0,0 +1,32 @@ +package com.squareup.test.demo + +import com.squareup.dagger.AppScope +import dev.zacsweers.metro.ContributesBinding +import dev.zacsweers.metro.ContributesTo +import dev.zacsweers.metro.Inject +import dev.zacsweers.metro.binding + +/** + * Reproduces a bug where @ContributesBinding contributions in the same module as a + * + * @DependencyGraph generated by an external FIR extension (@DevelopmentAppComponent) are not + * discovered during the SUPERTYPES phase. + * + * The @MetroContribution annotation's scope argument can't be resolved at the SUPERTYPES phase for + * same-module classes in real Gradle compilations, causing the contribution to be silently dropped. + */ +interface DemoService { + val name: String +} + +@Inject +@ContributesBinding(AppScope::class, binding = binding()) +class DemoServiceImpl : DemoService { + override val name: String = "contributed-binding" +} + +/** Exposes [DemoService] on the generated graph. */ +@ContributesTo(AppScope::class) +interface DemoServiceComponent { + val demoService: DemoService +} diff --git a/integration-tests/demo/src/test/kotlin/com/squareup/test/demo/DemoAppTest.kt b/integration-tests/demo/src/test/kotlin/com/squareup/test/demo/DemoAppTest.kt index 8bb73c5..2341cbf 100644 --- a/integration-tests/demo/src/test/kotlin/com/squareup/test/demo/DemoAppTest.kt +++ b/integration-tests/demo/src/test/kotlin/com/squareup/test/demo/DemoAppTest.kt @@ -4,6 +4,7 @@ import android.app.Application import com.squareup.development.shell.DevelopmentAppComponent import dev.zacsweers.metro.createGraphFactory import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.test.assertIs import kotlin.test.assertNotNull @@ -29,4 +30,16 @@ class DemoAppTest { val component = factory.create(Application()) assertNotNull(component) } + + @Test + fun `same-module ContributesBinding is discovered for generated DependencyGraph`() { + val factory = createGraphFactory() + val component = factory.create(Application()) + // This verifies that DemoServiceImpl's @ContributesBinding(AppScope::class) is properly + // merged into the MetroComponent generated by @DevelopmentAppComponent. Without the + // name-based fallback in ContributedInterfaceSupertypeGenerator, the scope resolution + // fails during the SUPERTYPES phase and DemoService cannot be provided. + val service = (component as DemoServiceComponent).demoService + assertEquals("contributed-binding", service.name) + } }