2424
2525
2626[@@@ ocaml.warning " +9" ]
27+ (* record pattern match complete checker*)
2728
2829
29-
30- let variant_can_bs_unwrap_fields row_fields =
30+ let variant_can_bs_unwrap_fields (row_fields : Parsetree.row_field list ) : bool =
3131 let validity =
3232 List. fold_left
3333 begin fun st row ->
@@ -60,7 +60,8 @@ let variant_can_bs_unwrap_fields row_fields =
6060 ]}
6161 The result type would be [ hi:string ]
6262*)
63- let get_arg_type ~nolabel optional
63+ let get_arg_type
64+ ~nolabel optional
6465 (ptyp : Ast_core_type.t ) :
6566 External_arg_spec. attr * Ast_core_type. t =
6667 let ptyp =
@@ -71,12 +72,8 @@ let get_arg_type ~nolabel optional
7172 if optional then
7273 Bs_syntaxerr. err ptyp.ptyp_loc Invalid_underscore_type_in_external
7374 else begin
74- let ptyp_attrs =
75- ptyp.Parsetree. ptyp_attributes
76- in
77- let result =
78- Ast_attributes. iter_process_bs_string_or_int_as ptyp_attrs
79- in
75+ let ptyp_attrs = ptyp.ptyp_attributes in
76+ let result = Ast_attributes. iter_process_bs_string_or_int_as ptyp_attrs in
8077 (* when ppx start dropping attributes
8178 we should warn, there is a trade off whether
8279 we should warn dropped non bs attribute or not
@@ -85,7 +82,6 @@ let get_arg_type ~nolabel optional
8582 match result with
8683 | None ->
8784 Bs_syntaxerr. err ptyp.ptyp_loc Invalid_underscore_type_in_external
88-
8985 | Some (`Int i ) ->
9086 Arg_cst (External_arg_spec. cst_int i), Ast_literal. type_int ~loc: ptyp.ptyp_loc ()
9187 | Some (`Str i )->
@@ -97,44 +93,34 @@ let get_arg_type ~nolabel optional
9793 end
9894 else (* ([`a|`b] [@bs.string]) *)
9995 let ptyp_desc = ptyp.ptyp_desc in
100- match Ast_attributes. process_bs_string_int_unwrap_uncurry ptyp.ptyp_attributes with
101- | (`String , ptyp_attributes)
102- ->
96+ (match Ast_attributes. iter_process_bs_string_int_unwrap_uncurry ptyp.ptyp_attributes with
97+ | `String ->
10398 begin match ptyp_desc with
10499 | Ptyp_variant ( row_fields, Closed , None )
105- ->
106- let attr =
107- Ast_polyvar. map_row_fields_into_strings ptyp.ptyp_loc row_fields in
108- attr,
109- {ptyp with
110- ptyp_attributes
111- }
100+ ->
101+ Ast_polyvar. map_row_fields_into_strings ptyp.ptyp_loc row_fields
112102 | _ ->
113103 Bs_syntaxerr. err ptyp.ptyp_loc Invalid_bs_string_type
114104 end
115- | ( `Ignore, ptyp_attributes ) ->
116- ( Ignore , {ptyp with ptyp_attributes})
117- | ( `Int , ptyp_attributes ) ->
105+ | `Ignore ->
106+ Ignore
107+ | `Int ->
118108 begin match ptyp_desc with
119109 | Ptyp_variant ( row_fields , Closed, None) ->
120110 let int_lists =
121111 Ast_polyvar. map_row_fields_into_ints ptyp.ptyp_loc row_fields in
122- Int int_lists ,
123- {ptyp with
124- ptyp_attributes
125- }
112+ Int int_lists
126113 | _ -> Bs_syntaxerr. err ptyp.ptyp_loc Invalid_bs_int_type
127114 end
128- | (`Unwrap, ptyp_attributes ) ->
129-
115+ | `Unwrap ->
130116 begin match ptyp_desc with
131- | ( Ptyp_variant (row_fields, Closed , _) as ptyp_desc )
117+ | Ptyp_variant (row_fields, Closed , _)
132118 when variant_can_bs_unwrap_fields row_fields ->
133- Unwrap , {ptyp with ptyp_desc; ptyp_attributes}
119+ Unwrap
134120 | _ ->
135121 Bs_syntaxerr. err ptyp.ptyp_loc Invalid_bs_unwrap_type
136122 end
137- | ( `Uncurry opt_arity , ptyp_attributes ) ->
123+ | `Uncurry opt_arity ->
138124 let real_arity = Ast_core_type. get_uncurry_arity ptyp in
139125 (begin match opt_arity, real_arity with
140126 | Some arity , `Not_function ->
@@ -147,9 +133,8 @@ let get_arg_type ~nolabel optional
147133 if n <> arity then
148134 Bs_syntaxerr. err ptyp.ptyp_loc (Inconsistent_arity (arity,n))
149135 else Fn_uncurry_arity arity
150-
151- end , {ptyp with ptyp_attributes})
152- | (`Nothing, ptyp_attributes ) ->
136+ end )
137+ | `Nothing ->
153138 begin match ptyp_desc with
154139 | Ptyp_constr ({txt = Lident " unit" ; _}, [] )
155140 -> if nolabel then Extern_unit else Nothing
@@ -160,7 +145,7 @@ let get_arg_type ~nolabel optional
160145 Nothing
161146 | _ ->
162147 Nothing
163- end , ptyp
148+ end ) , ptyp
164149
165150
166151
0 commit comments