Skip to content

Commit 3f4af12

Browse files
SamChou19815facebook-github-bot
authored andcommitted
[flow] Show signature verification errors for builtin type sig
Summary: It turns out we are not exposing these errors at all. For libdefs it's mostly fine since things like `const foo = new Set()` is already banned, but it will be important for the next diff where I raise new kinds of errors. Changelog: [errors] Signature verification errors will now show up for libdef files Reviewed By: gkz Differential Revision: D70303552 fbshipit-source-id: ce37ed169b8c7ecc47a801f302e4a887b371080f
1 parent 0cbd61d commit 3f4af12

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

src/flow_dot_js.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ let load_lib_files files =
8383
locs_to_dirtify = [];
8484
}
8585
in
86-
Merge_js.merge_lib_files ~sig_opts asts |> snd
86+
let (_, _, master_cx) = Merge_js.merge_lib_files ~sig_opts asts in
87+
master_cx
8788

8889
let stub_metadata ~root ~checked =
8990
{

src/services/inference/init_js.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let load_lib_files ~ccx ~options ~reader files =
4545
let (builtin_exports, master_cx, cx_opt) =
4646
if ok then
4747
let sig_opts = Type_sig_options.builtin_options options in
48-
let (builtins, master_cx) = Merge_js.merge_lib_files ~sig_opts ordered_asts in
48+
let (builtins, builtin_errors, master_cx) = Merge_js.merge_lib_files ~sig_opts ordered_asts in
4949
let cx_opt =
5050
match master_cx with
5151
| Context.EmptyMasterContext -> None
@@ -66,6 +66,7 @@ let load_lib_files ~ccx ~options ~reader files =
6666
(fun mref -> Context.MissingModule mref)
6767
mk_builtins
6868
in
69+
Context.reset_errors cx builtin_errors;
6970
Some cx
7071
in
7172
(Exports.of_builtins builtins, master_cx, cx_opt)

src/typing/__tests__/type_hint_test.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ end = struct
181181
locs_to_dirtify = [];
182182
}
183183
in
184-
Merge_js.merge_lib_files ~sig_opts asts |> snd
184+
let (_, _, master_cx) = Merge_js.merge_lib_files ~sig_opts asts in
185+
master_cx
185186

186187
let master_cx_ref = ref None
187188

src/typing/merge_js.ml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,14 +866,36 @@ let module_type_copied dst_cx src_cx ({ Type.module_export_types; module_global_
866866
{ m with Type.module_global_types_tmap }
867867

868868
let merge_lib_files ~sig_opts ordered_asts =
869-
let (_builtin_errors, builtin_locs, builtins) =
869+
let (builtin_errors, builtin_locs, builtins) =
870870
Type_sig_utils.parse_and_pack_builtins sig_opts ordered_asts
871871
in
872+
let builtin_errors =
873+
builtin_errors
874+
|> Base.List.filter_map ~f:(function
875+
| Type_sig.SigError e ->
876+
let e =
877+
Signature_error.map
878+
(fun l -> l |> Type_sig_collections.Locs.get builtin_locs |> ALoc.of_loc)
879+
e
880+
in
881+
let msg = Error_message.ESignatureVerification e in
882+
let source_file =
883+
Base.Option.value_exn
884+
(msg |> Error_message.loc_of_msg |> Base.Option.bind ~f:ALoc.source)
885+
in
886+
Some (Flow_error.error_of_msg ~source_file msg)
887+
| Type_sig.CheckError -> None
888+
)
889+
|> Flow_error.ErrorSet.of_list
890+
in
872891
match ordered_asts with
873-
| [] -> (builtins, Context.EmptyMasterContext)
892+
| [] -> (builtins, builtin_errors, Context.EmptyMasterContext)
874893
| fst_ast :: _ ->
875894
let builtin_leader_file_key = Base.Option.value_exn (fst_ast |> fst |> Loc.source) in
876-
(builtins, Context.NonEmptyMasterContext { builtin_leader_file_key; builtin_locs; builtins })
895+
( builtins,
896+
builtin_errors,
897+
Context.NonEmptyMasterContext { builtin_leader_file_key; builtin_locs; builtins }
898+
)
877899

878900
let mk_builtins metadata master_cx =
879901
match master_cx with

src/typing/merge_js.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ val copy_into :
2828
val merge_lib_files :
2929
sig_opts:Type_sig_options.t ->
3030
(Loc.t, Loc.t) Flow_ast.Program.t list ->
31-
Type_sig_collections.Locs.index Packed_type_sig.Builtins.t * Context.master_context
31+
Type_sig_collections.Locs.index Packed_type_sig.Builtins.t
32+
* Flow_error.ErrorSet.t
33+
* Context.master_context
3234

3335
val mk_builtins : Context.metadata -> Context.master_context -> Context.t -> Builtins.t

0 commit comments

Comments
 (0)