Why is this code working?
<?hh // strict
function test(Vector<int> $v):void {
print_r($v);
}
test(Vector {1, array("I'm an array"), 3});
Shouldn't it throw an error? What is the <int>
supposed to be for?
This won't throw an error in HHVM, but will in the Hack tools. This is due to HHVM currently ignoring generics, so it is just checking if $v
is a Vector
.
Running the Hack tools (hh_client
) will first complain about the top level statements and, if you correct that by wrapping the call to test
inside a function, will correctly complain about trying to pass a Vector<mixed>
as a Vector<int>
.