Skip to content
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

[js] Wrong auto-generated constructor for a child class with rest args in constructor #11426

Open
RealyUniqueName opened this issue Dec 8, 2023 · 1 comment
Labels
bug platform-javascript Everything related to JS / JavaScript

Comments

@RealyUniqueName
Copy link
Member

class Main extends Base {
	static function main() {
		new Main(); //should not print anything
	}
}

class Base {
	public function new(...args:Any) {
		for(arg in args) {
			trace(arg);
		}
	}
}
$ haxe --main Main --js test.js && node test.js
Main.hx:11: []

because

var Main = function() {
	var $l=arguments.length;
	var args = new Array($l>0?$l-0:0);
	for(var $i=0;$i<$l;++$i){args[$i-0]=arguments[$i];}
	Base.call(this,args); //this should be generated as Base.apply(this, args)
};
@RealyUniqueName RealyUniqueName added bug platform-javascript Everything related to JS / JavaScript labels Dec 8, 2023
@Simn
Copy link
Member

Simn commented Dec 13, 2023

Of note: with -D js-es=6 we get this output which behaves the same way:

class Base {
	constructor(...args) {
		let _g_current = 0;
		let _g_args = args;
		while(_g_current < _g_args.length) {
			let arg = _g_args[_g_current++];
			console.log("source/Main.hx:10:",arg == null ? "null" : Std.string(arg));
		}
	}
}
class Main extends Base {
	constructor(...args) {
		super(args);
	}
	static main() {
		new Main();
	}
}

I don't know what the fix for this one is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug platform-javascript Everything related to JS / JavaScript
Projects
None yet
Development

No branches or pull requests

2 participants