From 8b29a1f4c014c39e8d8d44301689928464d67f06 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Wed, 1 May 2024 13:53:23 -0700 Subject: [PATCH] [flow] Make builtin lookup's any from error have a generic `RImplicitAny` description Summary: Since it's any, these description won't be visible to user in any ways. So let's just give it a more generic description, instead of letting callsites construct one without understanding the requirement. Changelog: [internal] Reviewed By: panagosg7 Differential Revision: D56799561 fbshipit-source-id: 571e16d32bb44d52d2e8e3b34bb9165a40ee53fc --- src/typing/flow_js_utils.ml | 19 ++++++++++--------- src/typing/type_annotation.ml | 5 ++--- src/typing/type_operation_utils.ml | 6 +++--- src/typing/type_sig_merge.ml | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/typing/flow_js_utils.ml b/src/typing/flow_js_utils.ml index 97c2ad63478..1a26dbdc186 100644 --- a/src/typing/flow_js_utils.ml +++ b/src/typing/flow_js_utils.ml @@ -746,7 +746,7 @@ let emit_cacheable_env_error cx loc err = in add_output cx err -let lookup_builtin_module_error cx module_name reason = +let lookup_builtin_module_error cx module_name loc = let potential_generator = Context.missing_module_generators cx |> Base.List.find ~f:(fun (pattern, _) -> Str.string_match pattern module_name 0) @@ -754,25 +754,26 @@ let lookup_builtin_module_error cx module_name reason = in add_output cx - (Error_message.EBuiltinModuleLookupFailed - { loc = loc_of_reason reason; potential_generator; name = module_name } - ); - AnyT.error_of_kind UnresolvedName reason + (Error_message.EBuiltinModuleLookupFailed { loc; potential_generator; name = module_name }); + AnyT.error_of_kind UnresolvedName (mk_reason RAnyImplicit loc) -let lookup_builtin_name_error name reason = - Error (AnyT.error_of_kind UnresolvedName reason, Nel.one (Env_api.BuiltinNameLookupFailed name)) +let lookup_builtin_name_error name loc = + Error + ( AnyT.error_of_kind UnresolvedName (mk_reason RAnyImplicit loc), + Nel.one (Env_api.BuiltinNameLookupFailed name) + ) let lookup_builtin_value_result cx x reason = let builtins = Context.builtins cx in match Builtins.get_builtin_value_opt builtins x with | Some t -> Ok (TypeUtil.mod_reason_of_t (Base.Fn.const reason) t) - | None -> lookup_builtin_name_error x reason + | None -> lookup_builtin_name_error x (loc_of_reason reason) let lookup_builtin_type_result cx x reason = let builtins = Context.builtins cx in match Builtins.get_builtin_type_opt builtins x with | Some t -> Ok (TypeUtil.mod_reason_of_t (Base.Fn.const reason) t) - | None -> lookup_builtin_name_error x reason + | None -> lookup_builtin_name_error x (loc_of_reason reason) let apply_env_errors cx loc = function | Ok t -> t diff --git a/src/typing/type_annotation.ml b/src/typing/type_annotation.ml index da2b6cf8d0a..64cbf775cef 100644 --- a/src/typing/type_annotation.ml +++ b/src/typing/type_annotation.ml @@ -1019,13 +1019,12 @@ module Make (ConsGen : Type_annotation_sig.ConsGen) (Statement : Statement_sig.S } ) -> let { Ast.StringLiteral.value; _ } = str_lit in - let reason = mk_annot_reason (RCommonJSExports value) loc in - let remote_module_t = Flow_js_utils.get_builtin_module cx value reason in + let remote_module_t = Flow_js_utils.get_builtin_module cx value loc in let str_t = mk_singleton_string str_loc value in reconstruct_ast (Type_operation_utils.Import_export.cjs_require_type cx - reason + (mk_annot_reason (RCommonJSExports value) loc) ~legacy_interop:false remote_module_t ) diff --git a/src/typing/type_operation_utils.ml b/src/typing/type_operation_utils.ml index 47bfc1407b6..c24acb3a6f4 100644 --- a/src/typing/type_operation_utils.ml +++ b/src/typing/type_operation_utils.ml @@ -49,17 +49,17 @@ module Import_export = struct Flow_js_utils.add_output cx message let get_module_t cx ?(perform_platform_validation = false) (loc, mref) = - let reason = Reason.(mk_reason (RCustom mref) loc) in if Context.in_declare_module cx then - Flow_js_utils.get_builtin_module cx mref reason + Flow_js_utils.get_builtin_module cx mref loc else let module_t = match Context.find_require cx mref with | Ok t -> t - | Error m_name -> Flow_js_utils.lookup_builtin_module_error cx m_name reason + | Error m_name -> Flow_js_utils.lookup_builtin_module_error cx m_name loc in ( if perform_platform_validation && Files.multi_platform Context.((metadata cx).file_options) then + let reason = Reason.(mk_reason (RCustom mref) loc) in match Flow_js.possible_concrete_types_for_inspection cx reason module_t with | [ModuleT m] -> check_platform_availability cx reason m.module_available_platforms | _ -> () diff --git a/src/typing/type_sig_merge.ml b/src/typing/type_sig_merge.ml index 6a785dc6d01..3757028ad95 100644 --- a/src/typing/type_sig_merge.ml +++ b/src/typing/type_sig_merge.ml @@ -773,8 +773,8 @@ and merge_annot env file = function let id = eval_id_of_aloc file loc in Type.(EvalT (t1, TypeDestructorT (use_op, reason, RestType (Object.Rest.Sound, t2)), id)) | ExportsT (loc, ref) -> + let module_t = Flow_js_utils.get_builtin_module file.cx ref loc in let reason = Reason.(mk_annot_reason (RModule (OrdinaryName ref)) loc) in - let module_t = Flow_js_utils.get_builtin_module file.cx ref reason in ConsGen.cjs_require file.cx module_t reason false false | Conditional { loc; distributive_tparam; infer_tparams; check_type; extends_type; true_type; false_type }