0.11.2
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
@LazyClassKeyas 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
@RequiresIdeSupportopt-in message.
Fixes
- [IR]: Fix a code gen bug where
@Providesgraph 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
- Add docs link to
@RequiresIdeSupportwarning by @jonapoul in #1916 - Update GitHub Artifact Actions (major) by @renovate[bot] in #1917
- Update timestamps on ide caches to prevent re-downloads by @ZacSweers in #1918
- Report adhoc graph extension factories by @ZacSweers in #1897
- Report warning diagnostics for unused synthetic multibindings by @ZacSweers in #1919
- Update IDE version mappings by @ZacSweers in #1920
- Update plugin shadow to v9.3.1 by @renovate[bot] in #1923
- Update Gradle to v9.4.0-rc-2 by @renovate[bot] in #1922
- Fix FIR factory gen using wrong owner by @ZacSweers in #1924
- Update poko to v0.21.2 by @renovate[bot] in #1925
- Add KClass/Class interop for map keys by @ZacSweers in #1926
- Fix graph inputs being used in scoped bindings by @inorichi in #1921
- Update plugin shadow to v9.3.2 by @renovate[bot] in #1927
- Report diagnostic for LazyClassKey by @ZacSweers in #1929
- Include similar bindings when reporting suspicious unused multis by @ZacSweers in #1930
Full Changelog: 0.11.1...0.11.2