cincheo / jsweet

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

Parameter and local scopes mixed for overloaded constructors #732

Open vorth opened 1 year ago

vorth commented 1 year ago

This is a regression; it worked in 2.3.7.

Paste the following code into the live sandbox:

package org.jsweet;

import static def.dom.Globals.*;

public class IcosahedralSymmetryPerspective {

    private String aaa;

    public IcosahedralSymmetryPerspective( int xxx ) {
       // xxx here is clearly bound to the parameter definition, or should be,
       //   but JSweet claims we are accessing a variable before its definition.
       // Change the parameter name to yyy and you'll see why in the transpiled code.
        this( xxx + "" );
    }

    protected IcosahedralSymmetryPerspective( String bbb ) {
        this.aaa = bbb;

        int xxx = 99; // This is the local variable definition that collides incorrectly with the parameter in the other constructor
        System.out.println( xxx );
    }
}