Hello.
While struggling with another
problem already posted on this forum, I discovered an extrange behaviour of the Haxe Compiler I believe should be improved:
import haxe.ds.Vector;
class
Wrapper<
TElement
>
{
private var storage:Vector<TElement>;
public function new(length:Int):Void {
storage = new Vector<TElement>(length);
}
public function set(index:Int, value:TElement):Void {
storage[index] = value;
}
public function setNull(index:Int):Void {
storage[index] = null;
trace(storage);
}
}
class
Main
{
static public function main():Void {
thisCompiles();
// thisDoesNotCompile();
}
static public function thisCompiles():Void {
var w:Wrapper<Float> = new Wrapper<Float>(5);
w.set(0, 2.3);
w.set(1, 3.4);
w.setNull(0);
}
// static public function thisDoesNotCompile():Void {
// var v:Vector<Float> = new Vector<Float>(5);
// v[0] = 2.3;
// v[1] = 3.4;
// v[0] = null;
// trace(v);
// }
}
When compiling for a static target like C++ or SWF, the Haxe Compiler v3.2.1 admits the wrapper method, but fails for the other one. Curiosly, the wrapper method works perfectly when running the resulting executable.
Once the Wrapper type parameter has been forced into Float, the compiler should be able to check for a "Vector<Float> = null" and abort if that is the developers intention.
What do you think?