[solved] I find this Haxe type-mismatch error very confusing

Here’s the code-fragment in question:

typedef WFSubmapID = Int; private var _currentSubmap: MDSubmap; private var _submaps: Map(WFSubmapID, IMDMap); ... _currentSubmap = _submaps[id]; *(showing parentheses in the `Map` declaration above, where angle-brackets obviously are, because the `` tag doesn't seem to like `< >` characters)*

MDSubmap is a descendent of a parent-class which (the parent …) implements IMDMap.

Anyhow, the type-error message that I get is:
Null<MDMap> should be MDSubmap
``^^^^^^`

I’ve added the arrows to point-out exactly what it is that I don’t grok in that message … Null<...>

I frankly don’t understand what Haxe is trying to tell me here. I seem to vaguely remember this in the context of “dynamics,” but of course that’s not what I’m doing here, This is for the JavaScript target, and maybe Haxe’s trying to refer to what’s sort-of described in this manual-page: http://haxe.org/manual/types-nullability.html. But I’m just not sure.

Maybe my confusion really comes from not seeing how these could be incompatible in the first place. I’ve been very, vey rigorous about declaring that the types of things are exactly the same, partly for clarity.

The Null pointer is mainly to aid in compiling to all targets, since all targets can reference null but not necessarily 64-bit floats (as an example, like in the JS target).

In this case, Null<MDMap> is because you’re trying to reference an IMDMap within submaps, but _currentSubmap is of type MDSubmap. You’re not actually inheriting IMDMap, an implementation is like saying “MDSubmap has a relationship with IMDMap”, not “MDSubmap IS A IMDMap”.

You can see the difference between between Inheritance and Implementations on the manual as well.

To solve your problem, you can either make IMDMap a class instead of an interface, and make your MDSubmap extend it. Or you can check to see if MDSubmap has the relationship, by doing this:

if (Std.is(MDSubmap, IMDMap)) {
    //MDSubmap is a IMDMap, do something
}

Well, it turns out that the answer to my question was on that manual-page about type compatibility.

It so happens that, elsewhere in that function, I had said: _currentSubmapID = null;. Therefore, being the all-seeing schoolmaster that it is, Haxe inferred (correctly) that the type was “nullable.” That the type of _currentSubmap was, in fact, Null<MDSubmap>, even though I had not declared it that way.

When I changed the declaration to var _currentSubmap : Null<MDSubmap>, the message disappeared.

(Although I have since revised the code to refer to a nullable “id” field, rather than a nullable object-variable.)

Now we know.