0

The following code compiles to Javascript and runs OK, http://try.haxe.org/#8C940

abstract Comparable(Dynamic) from Float from String {
  @:op(a<b) static function lt(a, b):Bool;
}

class Test {
  public static function min<T:Comparable>(t:T, t2:T):T { 
    return (t:Comparable) < (t2:Comparable) ? t : t2; 
  }
  static function main() {
    var a = min(1.1,2.2); //ok
    $type(a); //Float
    trace(a); //1.1
    var b = min(1,2); //ok
    $type(b); //Int
    trace(b); //1
    var c = min("a","b"); //ok
    $type(c); //String
    trace(c); //a

    //following will produce compilation error, correctly
    //min(0, "a");
  }
}

But when compiled for neko, it gives the following error:

Main.hx:7: characters 12-13 : Unexpected :
Main.hx:7: characters 12-13 : Unexpected :
Uncaught exception - load.c(181) : Module not found : main.n

The error in question is line:

    return (t:Comparable) < (t2:Comparable) ? t : t2; 

Any ideas why the language featuer works in one target but not the other? And how can I fix the issue for neko?

Thanks.

thor
  • 21,418
  • 31
  • 87
  • 173

1 Answers1

1

i guess you have a compiler version conflict, can you try the latest development builds: http://hxbuilds.s3-website-us-east-1.amazonaws.com/builds/haxe/

(you can find the link here: http://haxe.org/manual/haxe3#git-builds -- edit: this page does not exist any more, but the build page is available via http://build.haxe.org)

kLabz
  • 1,837
  • 1
  • 14
  • 14
frabbit
  • 33
  • 5