Skip to content

Preserve Objective-C lightweight generics on instance @Property fields and record components. - #2910

Open
copybara-service[bot] wants to merge 1 commit into
masterfrom
test_1013969826
Open

copybara-service[bot] wants to merge 1 commit into
masterfrom
test_1013969826

Conversation

@copybara-service

Copy link
Copy Markdown

Preserve Objective-C lightweight generics on instance @Property fields and record components.

Previously, PropertyGenerator only preserved Objective-C generics on method-based @Property declarations and static companion properties (staticToInstance), while erasing generics on instance @Property fields (including all Java record component properties synthesized by RecordExpander). As a result, a Java record component such as Foo<Void> foo generated an erased @property (readonly, nonatomic) Foo *foo; alongside the generic accessor method - (Foo<JavaLangVoid *> *)foo;, causing Swift to import the property as Foo<AnyObject> instead of Foo<JavaLangVoid>.

In addition, NameTable.isTranslatableTypeVariable checked enclosingElement.getKind() != ElementKind.CLASS rather than !enclosingElement.getKind().isClass(), which caused type parameters on generic record declarations (ElementKind.RECORD) to be erased to id in member declarations even though @interface RecordName<T> declared <T>.

Update PropertyGenerator, HeaderImportCollector, and NameTable so non-static @Property fields and generic record components preserve Objective-C lightweight generics and forward-declare their generic type arguments when Objective-C generics are enabled.

…lds and record components.

Previously, `PropertyGenerator` only preserved Objective-C generics on method-based `@Property` declarations and static companion properties (`staticToInstance`), while erasing generics on instance `@Property` fields (including all Java `record` component properties synthesized by `RecordExpander`). As a result, a Java record component such as `Foo<Void> foo` generated an erased `@property (readonly, nonatomic) Foo *foo;` alongside the generic accessor method `- (Foo<JavaLangVoid *> *)foo;`, causing Swift to import the property as `Foo<AnyObject>` instead of `Foo<JavaLangVoid>`.

In addition, `NameTable.isTranslatableTypeVariable` checked `enclosingElement.getKind() != ElementKind.CLASS` rather than `!enclosingElement.getKind().isClass()`, which caused type parameters on generic `record` declarations (`ElementKind.RECORD`) to be erased to `id` in member declarations even though `@interface RecordName<T>` declared `<T>`.

Update `PropertyGenerator`, `HeaderImportCollector`, and `NameTable` so non-static `@Property` fields and generic `record` components preserve Objective-C lightweight generics and forward-declare their generic type arguments when Objective-C generics are enabled.

PiperOrigin-RevId: 1013969826

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant