I'm wondering why the following Haxe code compiles:
class Test<T> { // 1
var l:List<Dynamic> = new List<Dynamic>(); // 2
public function new() {} // 3
public function add(d:Dynamic):Void { l.add(d); } // 4
public function get():T { return l.pop(); } // 5
public static function main() { // 6
var t:Test<Int> = new Test<Int>(); // 7
t.add("-"); // 8
trace(t.get()); // 9
} // 10
}
The compilation problem I see:
As seen in line 1, this class has a type parameter T. In line 7, it is specified that T is an Int. So the get() function (line 5) should only return an Int. However - magically - this function returns a String (line 9).
So ... why doesn't the compiler complain about this?