From f8f652bd860dce781c27080eddffb3a1b98c4a34 Mon Sep 17 00:00:00 2001 From: Sasha Manzyuk Date: Tue, 26 Jun 2018 07:22:11 -0700 Subject: [PATCH] Improve typing of arrays containing untyped values Summary: When typing an array literal, if one of the values is untyped (i.e., has type the "any" type `_`), then we consider the entire array untyped (i.e., give it the value type `_`), but we do not check if the typed elements of the array have the types compatible with the expected type passed down from the context. This diff fixes this. Reviewed By: CatherineGasnier Differential Revision: D8537974 fbshipit-source-id: e9ff6df8613bddcd10b965448508be5226d2a49b --- hphp/hack/src/typing/typing.ml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hphp/hack/src/typing/typing.ml b/hphp/hack/src/typing/typing.ml index 04313e184eb..8c9a1ff2a2e 100644 --- a/hphp/hack/src/typing/typing.ml +++ b/hphp/hack/src/typing/typing.ml @@ -1331,15 +1331,14 @@ and expr_ match expected with | None -> Env.fresh_unresolved_type env | Some (_, _, ty) -> env, ty in - let has_unknown = List.exists tys (fun (_, ty) -> ty = Typing_utils.tany env) in let subtype_value env ty = Type.sub_type p Reason.URarray_value env ty supertype in - if has_unknown then + let env = List.fold_left tys ~init:env ~f:subtype_value in + if List.exists tys (fun (_, ty) -> ty = Typing_utils.tany env) then (* If one of the values comes from PHP land, we have to be conservative * and consider that we don't know what the type of the values are. *) env, (Reason.Rwitness p, Typing_utils.tany env) else - let env = List.fold_left tys ~init:env ~f:subtype_value in env, supertype in (** -- 2.11.4.GIT