Skip to content

Commit f745c16

Browse files
MarisaKirisamefacebook-github-bot
authored andcommitted
Add like type handling for can_index
Summary: Add cases for handling union and dynamic Differential Revision: D77729188 fbshipit-source-id: 7b9e6c911908ccef72d37ce811442953197ab522
1 parent ce5a52f commit f745c16

8 files changed

+47
-50
lines changed

hphp/hack/src/typing/typing_subtype.ml

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6158,7 +6158,7 @@ end = struct
61586158
~subtype_env
61596159
~this_ty
61606160
~lhs:{ sub_supportdyn; ty_sub }
6161-
~rhs:{ reason_super; can_index }
6161+
~rhs:({ reason_super; can_index } as rhs)
61626162
env =
61636163
let (env, ty_sub) = Env.expand_type env ty_sub in
61646164
let subtype_env =
@@ -6175,6 +6175,9 @@ end = struct
61756175
(ConstraintType
61766176
(mk_constraint_type (reason_super, Tcan_index can_index)))
61776177
in
6178+
let mk_prop ~subtype_env ~this_ty ~lhs ~rhs =
6179+
simplify ~subtype_env ~this_ty ~lhs ~rhs
6180+
in
61786181
let is_container tk tv =
61796182
Subtype.simplify
61806183
~subtype_env
@@ -6202,6 +6205,38 @@ end = struct
62026205
(LoclType ty_sub)
62036206
(ConstraintType
62046207
(mk_constraint_type (reason_super, Tcan_index can_index)))
6208+
| (_, Tdynamic) ->
6209+
Subtype.simplify
6210+
~subtype_env
6211+
~this_ty
6212+
~lhs:{ sub_supportdyn; ty_sub = MakeType.dynamic reason_super }
6213+
~rhs:
6214+
{
6215+
super_like = false;
6216+
super_supportdyn = false;
6217+
ty_super = can_index.ci_val;
6218+
}
6219+
env
6220+
&&&
6221+
if
6222+
Typing_env_types.(
6223+
TypecheckerOptions.enable_sound_dynamic env.genv.tcopt)
6224+
then
6225+
let subtype_env =
6226+
{ subtype_env with coerce = Some Typing_logic.CoerceToDynamic }
6227+
in
6228+
Subtype.simplify
6229+
~subtype_env
6230+
~this_ty
6231+
~lhs:{ sub_supportdyn; ty_sub = can_index.ci_key }
6232+
~rhs:
6233+
{
6234+
super_like = false;
6235+
super_supportdyn = false;
6236+
ty_super = MakeType.dynamic (get_reason ty_sub);
6237+
}
6238+
else
6239+
valid
62056240
| (_, Tclass ((_, n), _, [tv]))
62066241
when String.equal n SN.Collections.cVector
62076242
|| String.equal n SN.Collections.cVec
@@ -6218,6 +6253,17 @@ end = struct
62186253
->
62196254
is_container tkv tkv
62206255
| (_, Tvec_or_dict (tk, tv)) -> is_container tk tv
6256+
| (r_sub, Tunion ty_subs) ->
6257+
Common.simplify_union_l
6258+
~subtype_env
6259+
~this_ty
6260+
~mk_prop
6261+
~update_reason:
6262+
(Typing_env.update_reason ~f:(fun r_sub_prj ->
6263+
Typing_reason.prj_union_sub ~sub:r_sub ~sub_prj:r_sub_prj))
6264+
(sub_supportdyn, ty_subs)
6265+
rhs
6266+
env
62216267
| _ -> invalid ~fail env
62226268
end
62236269

@@ -6317,7 +6363,6 @@ end = struct
63176363
let mk_prop ~subtype_env ~this_ty ~lhs ~rhs =
63186364
simplify ~subtype_env ~this_ty ~lhs ~rhs
63196365
in
6320-
63216366
match deref lty_sub with
63226367
| (_, Tdynamic) when Subtype_env.coercing_from_dynamic subtype_env ->
63236368
valid env

hphp/hack/test/typecheck/constraint_array_index/after/lambda_called_on_2vec_curry.php.imp_pess_exp

Lines changed: 0 additions & 6 deletions
This file was deleted.

hphp/hack/test/typecheck/constraint_array_index/after/lambda_called_on_dict_vec.php.imp_pess_exp

Lines changed: 0 additions & 6 deletions
This file was deleted.

hphp/hack/test/typecheck/constraint_array_index/after/lambda_called_on_nested_immvector.php.imp_pess_exp

Lines changed: 0 additions & 6 deletions
This file was deleted.

hphp/hack/test/typecheck/constraint_array_index/after/lambda_called_on_nested_vector.php.imp_pess_exp

Lines changed: 0 additions & 6 deletions
This file was deleted.

hphp/hack/test/typecheck/constraint_array_index/after/lambda_called_on_vec_dict.php.imp_pess_exp

Lines changed: 0 additions & 6 deletions
This file was deleted.

hphp/hack/test/typecheck/constraint_array_index/after/lambda_called_on_vec_dict_keyset.php.imp_pess_exp

Lines changed: 0 additions & 12 deletions
This file was deleted.

hphp/hack/test/typecheck/constraint_array_index/after/lambda_called_on_vec_vec.php.imp_pess_exp

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)