hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

[Bug] hh_client doesn't recognize Map as a container when passed as argument

Open berle opened this issue 12 years ago • 2 comments

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.

berle avatar Apr 21 '14 18:04 berle

  • 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 to Map should 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.)

jwatzman avatar Apr 21 '14 18:04 jwatzman

A change is up for review internally to address this (internal ID: D1339407) -- thanks again for the report!

jwatzman avatar May 20 '14 18:05 jwatzman