FizzerWL / Cs2hx

C# to haXe converter
MIT License
58 stars 12 forks source link

Supplement for Limitations page #10

Closed Frederisk closed 1 year ago

Frederisk commented 1 year ago

Generic classes limitation

For generic classes with static methods which used common type parameters, for example:

// Class:
public static class MyClass<T, TR> {
    public static T[] Foo(int number, Object o=null) {
        return new T[number] ;
    }
}

// Usage:
String[] r = MyClass<String, Double>.Foo(1);

This will result in what appears to be problematic output:

// Class:
class MyClass<T, TR> {
    public static function Foo(number:Int, o:Dynamic = null):Array<T> {
/* <Error: "Unknown identifier : T">-------------------------------^ */
        return [  ];
    }
    public function new() {
    }
}

// Usage:
var r:Array<String> = consoleapp.MyClass.Foo(1);

But Cs2hx does not prompt any errors.

typeof

typeof is not available in most cases, except for a few methods of Enum. The exception message will appear:

System.Exception: typeof is not supported unless part of Enum.Parse or Enum.GetValues
FizzerWL commented 1 year ago

Thanks for the feedback!

I added the typeof limitation to the page. For the first one I do agree that you found a limitation and it deserves to be on this page, but my understanding of Haxe's generic system is pretty poor so I'm not sure how to describe exactly what the limitation is. Without knowing how to exactly describe it I won't add it page just yet.