HaxeFoundation / HaxeFoundation/haxe
Arrays are null in @:structInit classes
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
I expected this to create a 10 element array for `foo2` when i don't specify one in the argument list (like it assigns x=42), but currently it's just null.
```haxe
@:structInit class Point {
public final x = 42;
public final y: Int;
}
@:structInit class Foo {
public final points: Array = [for (i in 0...10) {}];
}
class Test {
static function main() {
final foo: Foo = { points: [{y: 1}] }
trace(foo.points.join(';'));
final foo2: Foo = {}
trace(foo2.points.join(';'));
}
}
```
JS output from http://try-haxe.mrcdk.com/#7d8e0
```js
// Generated by Haxe 4.1.0-rc.1+6cec2747e
(function ($global) { "use strict";
var Point = function(x,y) {
this.x = 42;
if(x != null) {
this.x = x;
}
this.y = y;
};
var Foo = function(points) {
this.points = null;
if(points != null) {
this.points = points;
}
};
var Test = function() { };
Test.main = function() {
console.log("root/program/Test.hx:13:",new Foo([new Point(null,1)]).points.join(";"));
console.log("root/program/Test.hx:15:",new Foo(null).points.join(";"));
};
var haxe_iterators_ArrayIterator = function(array) {
this.current = 0;
this.array = array;
};
haxe_iterators_ArrayIterator.prototype = {
hasNext: function() {
return this.current < this.array.length;
}
,next: function() {
return this.array[this.current++];
}
};
Test.main();
})({});
```
Contributor guide
Assessment
This issue has not been assessed yet.