cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.46k stars 160 forks source link

Nested generic anonymous classes support #557

Closed lgrignon closed 4 years ago

lgrignon commented 4 years ago

Trying to transpile the example from this comment: https://github.com/cincheo/jsweet/issues/519#issuecomment-569721715

will cause an error due to nested generic anonymous classes

lucgirardin commented 4 years ago

I indeed never tried to compile this class with version 2.x.

lgrignon commented 4 years ago

Fixed with https://github.com/cincheo/jsweet/commit/5c4d5afcba0a8f5657ed086d8e17682fa4c1bc98

But remains a bug, I opened another issue for it: https://github.com/cincheo/jsweet/issues/558

lgrignon commented 4 years ago

558 is fixed. There is still one bug to be fixed: https://github.com/cincheo/jsweet/issues/559

But we will face a second issue that I think would be difficult to fix: Your Iterable<T> conditional(..) method returns an Iterable<T>, which will transpiles to Array<T> but the new Iterable<T>() {} anonymous class which is returned won't actually transpile to an array in javascript (it will transpile to a new instance of a generated class matching this anonymous iterable prototype).

It would be nice to support those iterable/iterators with ES6+ generators, but it would require a non trivial amount of work.

lucgirardin commented 4 years ago

I can certainly find a workaround by rewriting this class. However, I am confused that you closed #559 with some code committed. Did you finally found a solution or is this just the indication that you are not going to dig it further?

lgrignon commented 4 years ago

No, #559 is indeed fixed. There was a regression in equals management with generic types

lucgirardin commented 4 years ago

It is maybe my mistake as I am not (yet) completely fluent with the JSweet build environment, but when I try to compile my class I get: org/jsweet/examples/iterable/Iterables.ts(9,20): error TS2322: Type 'Iterables$1<T>' is not assignable to type 'T[]'. type 'Iterables$1<T>' is not assignable to type 'T[]' at /Users/luc/java/jsweet-examples/src/main/java/org/jsweet/examples/iterable/Iterables.java(7) Property 'length' is missing in type 'Iterables$1<T>'. Happy to investigate further if the problem is likely to be on my side!

lgrignon commented 4 years ago

Oh, the remaining error is actually the one with the Iterable vs Array. I don't think there will be an easy fix so I recommend writing the code slightly differently if possible

lucgirardin commented 4 years ago

All clear now! Many thanks for all the hard work ;-)

lucgirardin commented 4 years ago

Seems that just converting the anonymous Iterable to an inner class is doing the trick... at least in term of getting a valid TS file as output :-)

lgrignon commented 4 years ago

You are welcome. Please keep me updated about wether it finally worked. Cheers