anvil icon indicating copy to clipboard operation
anvil copied to clipboard

Feature Request: Identify identical members from contributed components and override them

Open ZacSweers opened this issue 3 years ago • 1 comments

Consider this example

@MergeComponent(StartupScope::class)
@SingleIn(StartupScope::class)
interface StartupComponent {
  val okHttpClient: OkHttpClient
}

// Elsewhere
@ContributesTo(StartupScope::class)
interface ThingDependencies {
  val okHttpClient: OkHttpClient
}

Currently, this would fail to compile at component merging due to a missing override of okHttpClient. It would be ideal if anvil could identify these and add them as needed.

Note that qualifiers are considered part of the type, so @ForScope(AppScope::class) OkHttpClient and OkHttpClient would be different types and need to be deemed an error.

ZacSweers avatar Oct 07 '22 17:10 ZacSweers

Another edge case besides different qualifiers is that names could clash for different types. Functions need to be considered as well, e.g.

@MergeComponent(StartupScope::class)
@SingleIn(StartupScope::class)
interface StartupComponent {
  fun client(): OkHttpClient
}

// Elsewhere
@ContributesTo(StartupScope::class)
interface ThingDependencies {
  fun client(): AwsClient
}

(inheritance should be supported)

vRallev avatar Oct 07 '22 18:10 vRallev