HaxeFoundation/haxe

auto-generated ctors vs Rest args

nadako opened this issue · 8 comments

extern class A {
	function new(args:haxe.extern.Rest<Dynamic>);
}

class B extends A {}

will generate (JS, but also other targets, actually discovered on Flash):

var B = function(args) {
	A.call(this,args);
};

This probably should be handled in generators.

so we're (partially) implementing non-extern rest args?:)

Do we have any option currently to override extern methods with rest args?

Nope, also can't implement interfaces that require rest args.

I think I'll add support for Rest<T> in the Flash generator for now, because I need these subclasses to work correctly.

OTOH this is annoying because we have to detect the cases where we have to generate super.call(rest) on Flash...

Personally I think we should support rest args in Haxe syntax. All (afaik) our targets support rest arguments. And if some of them don't then it's ok to implement it as

@:coreType abstract Rest <T> { 
    @:to function toArray():Array<T>...

I'm not a fan of rest args and the implicit allocations they usually bring. Also I don't think C/C++ support rest arguments like this. Newer C++ has the ...args syntax, but it's just a sugar for some templating magic for recursive functions, not something you can just turn into Array.

That said, maybe we should still have it for the sake of interop, just not in a nicely sugared syntax.