-
Notifications
You must be signed in to change notification settings - Fork 976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Adventures in Obj-C Lightweight Generics... #2096
Comments
@tomball sorry it always takes me months to follow up... i'm scraping time when I can :) |
I believe this example class shows the problem, when converted with latest j2objc and
|
Attached a zip containing Scratch.java and the j2objc-generated Scratch.h and Scratch.m files. For reference, in the header file, the constructor is translated as:
which results in the error:
And in the .m file:
which results in:
|
Another example, in case its useful. |
Thanks for the feedback here, as it sounds like we have a way to go before this feature is usable. @litstrong is now the responsible engineer for this feature, so I'm sure you'll be hearing from him soon. |
Thanks @tomball - again apologies for the glacial pace of progress on my side! @litstrong FYI i think there are two distinct problems here, one of which is shown in each of the two example zip files. Firstly it seems that IOSClass should perhaps become generic itself, or else references to Class in java should be translated without the generic argument. The other problem is handling of user-written generic classes - Please let me know if i can be of assistance, including testing updates :) |
Thanks @mungler for your valuable feedback and sorry for my late response. The j2objc generics support (--objc-generics) is not fully implemented yet. So, looks like we have two issues in this thread:
Please let me know if my understanding is correct. |
Hi @litstrong i believe so, yes. Happy to test it out on a different branch or whatever, just let me know when you have something testable 👌 |
Hi @litstrong / @tomball just checking in to see if I can be of any assistance with testing things for this? Much appreciated. |
Hi Rory, apologize for slow response on this thread. I think we have good test examples from you to start, but was not able to prioritize it yet because the team is under-staffed at the moment and I'm busy with many things in parallel. But it is definitely on my plate, I'll try to spend time on it once I address some tasks with higher priority in my list. |
No worries, completely understand.
|
Hi @litstrong I was wondering if i might be able to tackle this, emboldened by having my first PR accepted and merged recently... :) How would you feel about me pinging you random questions and things when I get stuck? Do you have any pointers to where to look first? I can see that IOSClass.h in the jre_emul project will need updated to specify Let me know what you think! |
Hi Rory, defintely welcome to contribute! It is worth to mention new features for j2objc is lower priority to us given that we are expermenting Kotlin multiplatform. The future of j2objc needs to be evaluted based on the experiment results. I had one change here by supporting the annotation @GenerateObjectiveCGenerics, so that we only enable Generics conversion for the annotated types. I think that could be a good example to trace down to see how it works. |
@litstrong thats sad news! Can I ask what the migration path looks like for Google? Kotlin multiplatform or similar? |
Hi Rory, sorry, I think my statement was not accurate, just updated my previous comment. |
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:
the translation looks like:
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.
The text was updated successfully, but these errors were encountered: