Abstracts, implicit casts and externs

40 views
Skip to first unread message

Żabojad

unread,
Mar 29, 2016, 12:02:21 PM3/29/16
to Haxe
I'm having the following issue with abstracts implicit casting + extern EitherType : http://try.haxe.org/#44f74

Using abstract implicit casting in an extern method signature in fine. But if I use EitherType, it's not anymore...

Is that a bug or a known limitation?

Żabojad

unread,
Mar 29, 2016, 12:11:10 PM3/29/16
to Haxe
OK, that probably because haxe.extern. EitherType is already an abstract and we thus fall into this limitation:


While the individual casts from A to B and from B to C are allowed, a transitive cast from A to C is not. This is to avoid ambiguous cast-paths and retain a simple selection algorithm.

Could there be a metadata to deactivate this limitation? ^^ 

Żabojad

unread,
Mar 29, 2016, 12:26:33 PM3/29/16
to Haxe
Would there be a macro way to allow the casting of A => B => C ?

Żabojad

unread,
Mar 29, 2016, 12:54:02 PM3/29/16
to Haxe
I'm far from being a macro champion but I believe that would be feasible:

Can I attach some macro logic to an extern method definition so that every time it's used, it that would add an intermediate call to perform the conversion from A to B and from B to C ?

Something like:

extern class ExTest {
    @:build(myMacro.convert)
    static function test2(v : haxe.extern.EitherType<MyAbstractInt,SomethingElse>) : Void;
}

and MyMacro.convert would actually just wrap with, or add inline the conversion:

var arg : MyAbstractInt = T2;

ExTest.test2(arg);


Full example still available there : http://try.haxe.org/#44f74
Reply all
Reply to author
Forward
0 new messages