haxe icon indicating copy to clipboard operation
haxe copied to clipboard

Possible issue with function bind

Open rushmobius opened this issue 6 years ago • 1 comments

Using haxe 4 rc3 and hashlink 1.9 Giving a basic class structure like

class Node
{
    public function new()
    {
    }

    public function addNode<T:Node>(node:T):T
    {
        return node;
    }
}

class AnotherNode extends Node
{

}

The following code fails to compile with the error Don't know how to cast #Node to #AnotherNode

var s:Node = new Node();

s.addNode.bind(new AnotherNode());

This code compiles without issue on the flash/cpp targets. If i changed the <T:Node> to just <T> it works fine, but then I can't enforce a base type for the call. Another option that works is to change it to

public addNode<T:Node>(node:Node):T
{
return cast node;
}

Should this issue be added to the haxe github?

rushmobius avatar Sep 14 '19 20:09 rushmobius

This is actually a bug in the haxe compiler HL generation, should be fixed as it's not a platform limitation.

ncannasse avatar Sep 15 '19 08:09 ncannasse