HaxeFoundation / HaxeFoundation/haxe

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

Open
#11,426 1 comment 0 reactions 0 assignees View on GitHub
bug platform-javascript
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

```haxe
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
```js
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)
};
```

Contributor guide

Open the contributing guide

Research direction

Start by running the minimal Main/Base reproduction from the issue with Haxe's JavaScript target, then inspect the generated Main constructor and its Base call. Compare the rest-argument handling with the expected JavaScript call semantics. Done means new Main() produces no trace output and the generated constructor passes the arguments correctly to Base.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.