Type parameters are invariant : only with


I have maybe found a bug, or a behavior I can’t explain.

When I’m using, unification of my type parameters of my array fails with optional fields.

Here is a small chunk of code that reproduce the behavior. The first assignment fails, the second one passes but both shows the same result with $type.

What can I do to fix that ? Is that a bug related to Haxe itself ?

(Rudy Ges) #2

It’s not easy for the compiler to guess everything in this kind of scenario. But yeah, { c : Null<Int> } seems compatible with X in your case.

What you can do is add a little typing to your map function (notice the added :X):

var x = [1].map(function(a):X return {c: null});