@:from interface


I’m playing around with Haxe abstracts and am having a lot of fun with them. However, they don’t play nice with interfaces, or maybe i’m just not getting it!

Here is some example code. The @:from implicit cast does not play well with interfaces. c_loveshaxe will not compile!? Is there anything I can do to make it compile?

I’m using Haxe/HL but I’m assuming that it’s a generic thing.

Many thanks for any help on this.

// an interface
interface LovesHaxe {
    public var a: Int;

// a test class
class Test implements LovesHaxe {
    public var a: Int = 0;

    public function new(a: Int = 0) {
        this.a = a;

// abstract implementation
class ContainerImpl<T> {
    public var value(default, null): Null<T>;

    public function new(value: Null<T> = null) {

    public function set(value: Null<T>) {
        this.value = value;

// our abstract
abstract Container<T>(ContainerImpl<T>) from ContainerImpl<T> {

    public inline function new(value: Null<T> = null) {
        this = new ContainerImpl<T>(value);

    @:from static function fromT<T>(value: Null<T>): Container<T> {
        return new Container(value);

class SomeClass {
    public static function main() {
        var c_int: Container<Int> = 10;                         // good
        var c_test: Container<Test> = new Test(10);             // good!
        var c_loveshaxe: Container<LovesHaxe> = new Test(10);   // bad! Container dos not love haxe!