cincheo / jsweet

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

Constructor overloading issue #183

Open alievrenkut opened 7 years ago

alievrenkut commented 7 years ago

Hi,

First thank you for this awesome project. I like to report an issue with constructor overloading. This was not happening at version jsweet-transpiler-1.2.0-20161018.144151-38.jar I created a githup repo so you can easily recreate the issue: https://github.com/alievrenkut/jsweet-tests

Basically if we write below code:

`   public ConstructorTest (final OtherObject1 obj1) {
        this(obj1, new InnerTest());
    }

    public ConstructorTest (final OtherObject1 obj1, final InnerTest InnerTest) {
        this(obj1, InnerTest, createPrefix(obj1, InnerTest));
    }`

first constuctor will compile as:

`if(((obj1 != null && obj1 instanceof test.OtherObject1) || obj1 === null) && InnerTest === undefined && prefix === undefined && s1 === undefined && s2 === undefined) {
                let __args = Array.prototype.slice.call(arguments);
                {
                    let __args = Array.prototype.slice.call(arguments);
                    let InnerTest : any = new ConstructorTest.InnerTest();
                    {
                        let __args = Array.prototype.slice.call(arguments);
                        let prefix : any = ConstructorTest.createPrefix(__args[0], __args[1]); // there is no __args[1] exists. Second argument should be InnerTest 
                        {
                            let __args = Array.prototype.slice.call(arguments);
                            let s1 : any = __args[1].s1 != null?__args[1].s1:ConstructorTest.getDefault1();
                            let s2 : any = __args[1].s2 != null?__args[1].s2:ConstructorTest.getDefault2();
                        }
                    }
                }
            } `

There is problem with line: let prefix : any = ConstructorTest.createPrefix(__args[0], __args[1]); There is no __args[1] exists. Second argument should be InnerTest

Best Regards, Ali

renaudpawlak commented 7 years ago

Thanks for reporting. Overloading is quite tricky, especially constructor overloading. I'll work on it when possible (in the meantime you can certainly workaround the issue).