Skip to content

New Adventures in Obj-C Lightweight Generics... #2096

@mungler

Description

@mungler

Following on from #1947

I can now see that the converted source headers have generic information where applicable, e.g. a

private Monkey[] monkeys

field in the java source becomes:

IOSObjectArray<ABCMonkey *> monkeys

which is great!

The problem is that non-Collection classes are also being translated with generics... or perhaps the problem is that their generics are not being stripped?

I'm seeing two types of error when compiling our Obj-C library project with the --objc-generics flag enabled:

Type arguments cannot be applied to non-parameterized class 'Foo'

For example, we have a 'Resource' class, defined in Java as:

public class Resource<T>

with a constructor which takes a Class<T> argument:

public Resource(String key, Request request, Class<T> target) {

In the generated source, i'm seeing errors around this, e.g.:

Type arguments cannot be applied to non-parameterized class 'IOSClass' from this line:

- (instancetype __nonnull)initWithASWRequest:(ASWRequest *)request withIOSClass:(IOSClass<T> *)target;

Another issue shows up in a method on a class that uses the Resource class, defined in the java source as:

public void putResource(final String key, final Resource<?> resource) {
   resourcesMap.put(key, resource);
}

the translation looks like:

- (void)putResourceWithNSString:(NSString *)key
      withASWPresentersResource:(ASWPresentersResource<id> *)resource;

which gives:

Type arguments cannot be applied to non-parameterized class 'ASWPresentersResource'

I'm not totally sure what is wrong here, I think some things are being mistranslated, and the <T> references are being copied as-is, maybe?

As I understand it, in Obj-C, you're free to parameterise any class, whereas Swift will ignore any lightweight generics other than those on collection classes. Which is fine, but the project in question is Obj-C, not Swift (our app is Swift, but uses the translated code in the form of a static library).

I hope that makes some sort of sense. Please let me know if i can be of any assistance. I could possibly try to put together an example project that shows the problem.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions