Skip to content

Commit e4c6515

Browse files
Rename companion field to CompanionInstance instead of nested type
Switch approach: rename the static peer field rather than the nested companion type. Consumers now write e.g. `Color.CompanionInstance.Red` (instead of `Color.Companion.Red`), keeping the nested type name as the more accurate `<Outer>.Companion` that mirrors the Kotlin/Java source. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 90d2610 commit e4c6515

6 files changed

Lines changed: 656 additions & 656 deletions

File tree

source/androidx.compose.foundation/foundation-android/PublicAPI/PublicAPI.Unshipped.txt

Lines changed: 103 additions & 103 deletions
Large diffs are not rendered by default.

source/androidx.compose.foundation/foundation-android/Transforms/Metadata.xml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,19 @@
7373
<attr path="/api/package[@name='androidx.compose.foundation']/class[@name='MutationInterruptedException']" name="visibility">public</attr>
7474

7575
<!--
76-
Kotlin `object` companion on a `class`: the nested peer binds as
77-
`<Outer>.Companion`, which collides with the static `Companion` property the
78-
generator would otherwise emit on the outer class (a nested type and a
79-
property can't share a name), so the field is silently dropped and the
80-
singleton is only reachable via raw JNI. Rename every nested `*.Companion`
81-
peer to `CompanionStatic` (the same wildcard pattern kotlin-stdlib, okio,
82-
aicore, and genai-prompt already use) so the generator surfaces
83-
`public static <Outer>.CompanionStatic Companion { get; }` on every outer
84-
class, letting consumers write e.g. `KeyboardOptions.Companion.Default`,
85-
`ScrollState.Companion.Saver`, `LazyListState.Companion.Saver` directly.
86-
(Interface companions are hoisted to top-level `<Outer>Companion` by the
87-
generator before this rename matches, so they're unaffected.)
76+
Kotlin `object` companion on a `class`: the JVM emits a `public static
77+
Companion Companion;` field on the outer class plus a nested
78+
`<Outer>.Companion` peer type. C# can't have both a static member and a
79+
nested type with the same name, so the generator silently drops the static
80+
field and the singleton is only reachable via raw JNI. Rename the static
81+
field to `CompanionInstance` (leaving the nested type as
82+
`<Outer>.Companion`) so the generator emits
83+
`public static <Outer>.Companion CompanionInstance { get; }` on every outer
84+
class — `KeyboardOptions.CompanionInstance.Default`,
85+
`ScrollState.CompanionInstance.Saver`, `LazyListState.CompanionInstance.Saver`
86+
are now reachable directly. Interface companions are unaffected — the
87+
generator hoists their peer to top-level `<Outer>Companion` and emits a
88+
public `CompanionStatic` accessor that this rename doesn't match.
8889
-->
89-
<attr path="/api/package/class[substring(@name,string-length(@name)-9)='.Companion']" name="managedName">CompanionStatic</attr>
90+
<attr path="/api/package/class/field[@name='Companion' and substring(@type,string-length(@type)-9)='.Companion']" name="managedName">CompanionInstance</attr>
9091
</metadata>

0 commit comments

Comments
 (0)