Skip to content

Support map keys on contributed generic types and default bindings - #2592

Open
japplin wants to merge 2 commits into
ZacSweers:mainfrom
japplin:japplin/map-key-type-param
Open

Support map keys on contributed generic types and default bindings #2592
japplin wants to merge 2 commits into
ZacSweers:mainfrom
japplin:japplin/map-key-type-param

Conversation

@japplin

@japplin japplin commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds map key support for generic type arguments on @ContributesIntoMap bindings and @DefaultBinding type parameters.

@ContributesIntoMap(AppScope::class)
class HomeScreen : RouteScreen<@ClassKey HomeKey>

Default bindings can define the convention once:

@DefaultBinding<RouteScreen<*>>
interface RouteScreen<@ClassKey T : RouteKey>

@ContributesIntoMap(AppScope::class)
class HomeScreen : RouteScreen<HomeKey>

Metro resolves the resulting entry as HomeKey::class to HomeScreen.

Resolution behavior

Map keys are resolved in this order:

  1. Explicit binding type
  2. Contributed class
  3. Bound type generic argument
  4. @DefaultBinding type parameter

The default binding key is only a fallback. Keys declared by an implementation take precedence.

Metro reports an error when multiple declaration site locations provide a key or when multiple generic arguments or type parameters are annotated as map keys.

Metro also verifies that an implicit class key accepts the concrete generic type.

AI disclaimer: Most code and tests were generated with 5.6 Sol, I've done several passes of refactoring.

japplin added 2 commits July 26, 2026 21:20
Allow @ContributesIntoMap to derive map keys from generic type arguments
or @DefaultBinding type parameters, including across modules.

Implementation site keys take precedence over default keys. Reject
conflicting key locations and multiple keyed type arguments.
Verify implicit class keys accept the concrete generic type used by
@ContributesIntoMap and @DefaultBinding implementations.

Reject multiple map keys on a generic argument and validate
@DefaultBinding type parameter key uniqueness at the declaration site.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant