Skip to content

0.11.2

Choose a tag to compare

@ZacSweers ZacSweers released this 02 Mar 05:57
· 898 commits to main since this release

New

Class/KClass map key interop

This release introduces a special-cased opt-in java.lang.Class and kotlin.reflect.KClass interop on JVM/android compilations. While these types are not intrinsics of each other in regular code, they are in annotations and are often used in Map multibindings. Metro can support these if you enable the enableKClassToClassMapKeyInterop option. When enabled, java.lang.Class and kotlin.reflect.KClass are treated as interchangeable in map key types, matching Kotlin's own annotation compilation behavior. This only applies to map keys because these are the only scenario where annotation arguments are materialized into non-annotation code (i.e. @ClassKey(Foo::class) -> Map<Class<*>, V>).

This is disabled by default (even if other framework interops like includeDagger are enabled) because this is purely for annotations interop and potentially comes at some runtime overhead cost to interop since KClass types are still used under the hood and must be mapped in some cases. It's recommended to migrate these to KClass and call .java where necessary if possible.

Enhancements

  • [FIR]: Report adhoc graph extension factories as these are unsupported in Metro (but apparently supported in Dagger!)
  • [FIR]: Report a diagnostic error for usage of Dagger's @LazyClassKey as this is unsupported in Metro.
  • [IR]: Report warning diagnostics for unused synthetic multibindings, as it's often a sign that the user accidentally bound them to the wrong supertype.
    warning: [Metro/SuspiciousUnusedMultibinding] Synthetic multibinding kotlin.collections.Map<kotlin.reflect.KClass<*>, BaseViewModel> is unused but has 4 source binding(s). Did you possibly bind them to the wrong type?
    
      SuspiciousUnusedMultibinding.kt:36:1
        HomeViewmodel contributes a binding of BaseViewModel
                                               ~~~~~~~~~~~~~
      SuspiciousUnusedMultibinding.kt:31:1
        AccountViewModel contributes a binding of BaseViewModel
                                                  ~~~~~~~~~~~~~
      SuspiciousUnusedMultibinding.kt:26:1
        SettingsViewModel contributes a binding of BaseViewModel
                                                   ~~~~~~~~~~~~~
      ...and 1 more
    
    Similar multibindings:
    - Map<KClass<*>, ViewModel>
    
  • [Gradle]: Add IDE support docs link to @RequiresIdeSupport opt-in message.

Fixes

  • [IR]: Fix a code gen bug where @Provides graph parameters wouldn't correctly be used by scoped bindings directly held in that graph.

Contributors

Special thanks to the following contributors for contributing to this release!

What's Changed

Full Changelog: 0.11.1...0.11.2