hhvm
hhvm copied to clipboard
[Bug] hh_client doesn't recognize Map as a container when passed as argument
When passing a Map container as argument to a function, hh_client will not recognize that it's a container and not allow $map["foo"] type syntax on it:
This is not a container, this is an object of type Map
The following code should reproduce the issue.
<?hh
function foo(Map $map): Map
{
// Fails hh_client
$map["foo"] = "bar";
return $map;
}
$map = foo(Map {});
// Doesn't fail hh_client
$map["fun"] = "fan";
This example is without classes and other fluff, but the problem occurs in "proper" code as well.
- You should specify the key and value types of the
Map, e.g.,function foo(Map<string, string> $map): Map<string, string>. In some cases omitting these is legal in partial mode -- I think this is one of those cases. If so, we should allow the assignment; if not, we should give an appropriate error. So, looks like a bug here at first glance, but adding the type parameters toMapshould help you work around. I'm not sure when I'll have time to look into this, so if you want to do so yourself and send us a PR to fix, please do so :) - We don't typecheck anything in a pseudomain, which is why the second example doesn't produce an error. This is intended and not a bug. (Due to globals, pseudomain is impossible to typecheck. This wouldn't be admitted in strict mode however.)
A change is up for review internally to address this (internal ID: D1339407) -- thanks again for the report!