New Adventures in Obj-C Lightweight Generics...
- Dominant language
- Java
- Stars
- 6k
- Forks
- 999
- Avg merge
- 19h 20m
- Merged PRs (30d)
- 14
Description
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 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```
with a constructor which takes a `Class` argument:
```public Resource(String key, Request request, Class 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 *)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 *)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 `` 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.
Contributor guide
Assessment
This issue has not been assessed yet.