Reputation: 21
Trying to fix a HH complain... Basically the code is doing something similar to this
Sfirstgroup = idx($largegroup, "first");
$final_thing = null
if(HH\is_any_array(Sfirstgroup) && Sfirstgroup){
/*HH_FIXME[4110] Error revealed by is_arry refining to varray_or_darray */
$final_thing = idx(Sfirstgroup[0],"final_thing")
}
I think it must have some thing to with firstgroup[0] doesn't have a collection type. but couldn't figure out how to fix this...
Thanks a lot!
Upvotes: 2
Views: 168
Reputation: 3187
You have two type errors:
$firstgroup[0]
doesn't work very well with the inferred type from is_any_array
, which infers wildcard generics for the key type (i.e. it's a KeyedContainer<_,_>
). Either change $a[0]
to idx($a, 0)
or use is_vec_or_varray
if all your keys are int
, since it refines to vec<_>
.$firstgroup[0]
is a KeyedContainer
to use your second idx
call for $final_thing
. The refinement checks like is_any_array
won't work on an indexed variable (like $firstgroup[0]
), so you have to make a temporary variable to refine it.All in all, here's one possible solution:
$firstgroup = idx($largegroup, "first");
$final_thing = null;
if(HH\is_vec_or_varray($firstgroup)){
$first_item = $firstgroup[0];
if(HH\is_any_array($first_item)) {
$final_thing = idx($first_item,"final_thing");
}
}
Upvotes: 2