cincheo / jsweet

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

Mixin methods loose generic types #73

Closed lgrignon closed 8 years ago

lgrignon commented 8 years ago

For instance in candy cordova--plugins-FileSystem-0.0.0-SNAPSHOT jsweet.dom.Window has a mixin defining this method :

native public void requestFileSystem(double type, double size, java.util.function.Consumer<FileSystem> successCallback, java.util.function.Consumer<FileError> errorCallback);

but it seems that the signature added to jsweet.dom.Window is

native public void requestFileSystem(double type, double size, java.util.function.Consumer<Object> successCallback, java.util.function.Consumer<Object> errorCallback);

Note that the Consumers - callbacks - parameters are now typed with Object

The following code does not work, the compiler complains about the wrong Consumers parameter type:

import def.cordova.plugins.FileError;
import def.cordova.plugins.FileSystem;
// [...]
window.requestFileSystem(
                            window.PERSISTENT,
                            1000*1000,
                            (FileSystem fileSystem) -> {
                                console.log("FileSystem ready");
                            },
                            (FileError error) -> console.log("bad error", error));
renaudpawlak commented 8 years ago

I am surprised, but the solution should be Javassist's setGenericSignature: http://jboss-javassist.github.io/javassist/html/javassist/CtBehavior.html#setGenericSignature-java.lang.String-

lgrignon commented 8 years ago

okay, I have a fix thanks to your insight.

This "detail" fixes some signature problems so it may cause regression on some client code.

Related PR: https://github.com/cincheo/jsweet/pull/77

renaudpawlak commented 8 years ago

Thanks Louis. The fix looks good (and simple) to me. If regression there is, it should be easy to fix for users.