Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<DemoService>())
class DemoServiceImpl : DemoService {
override val name: String = "contributed-binding"
}

/** Exposes [DemoService] on the generated graph. */
@ContributesTo(AppScope::class)
interface DemoServiceComponent {
val demoService: DemoService
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<DemoApp.MetroComponent.Factory>()
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)
}
}
Loading