I am not sure if this is a bug or intended. At least I don't understand it:
typedef Foo = {
x: Int,
? y: String,
}
class Test {
static var a = [{x:1}, {x:2}];
static function test1(): Array<Foo> {
$type(a); // Test.hx:10: characters 14-15 : Warning : Array<{ x : Int }>
return a;
}
static function test2(): Array<Foo> {
var b = new Array<{x: Int}>();
$type(b); // Test.hx:16: characters 14-15 : Warning : Array<{ x : Int }>
b = a;
return b; // Haxe complains here.
}
static function main() {
trace("Haxe is great!");
var aa = test1();
trace(aa);
var bb = test2();
trace(bb);
}
}
Test.hx:18: characters 8-16 : Array<{ x : Int }> should be Array<Foo>
Test.hx:18: characters 8-16 : Type parameters are invariant
Test.hx:18: characters 8-16 : { x : Int } should be Foo
Test.hx:18: characters 8-16 : { x : Int } should be { ?y : Null<String>, x : Int }
Test.hx:18: characters 8-16 : { x : Int } has no field y
from what $type tells me both a and b have the same type, why does this not work ? I am quite sure this did work at earlier release.