24
24
25
25
26
26
[@@@ ocaml.warning " +9" ]
27
+ (* record pattern match complete checker*)
27
28
28
29
29
-
30
- let variant_can_bs_unwrap_fields row_fields =
30
+ let variant_can_bs_unwrap_fields (row_fields : Parsetree.row_field list ) : bool =
31
31
let validity =
32
32
List. fold_left
33
33
begin fun st row ->
@@ -60,7 +60,8 @@ let variant_can_bs_unwrap_fields row_fields =
60
60
]}
61
61
The result type would be [ hi:string ]
62
62
*)
63
- let get_arg_type ~nolabel optional
63
+ let get_arg_type
64
+ ~nolabel optional
64
65
(ptyp : Ast_core_type.t ) :
65
66
External_arg_spec. attr * Ast_core_type. t =
66
67
let ptyp =
@@ -71,12 +72,8 @@ let get_arg_type ~nolabel optional
71
72
if optional then
72
73
Bs_syntaxerr. err ptyp.ptyp_loc Invalid_underscore_type_in_external
73
74
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
80
77
(* when ppx start dropping attributes
81
78
we should warn, there is a trade off whether
82
79
we should warn dropped non bs attribute or not
@@ -85,7 +82,6 @@ let get_arg_type ~nolabel optional
85
82
match result with
86
83
| None ->
87
84
Bs_syntaxerr. err ptyp.ptyp_loc Invalid_underscore_type_in_external
88
-
89
85
| Some (`Int i ) ->
90
86
Arg_cst (External_arg_spec. cst_int i), Ast_literal. type_int ~loc: ptyp.ptyp_loc ()
91
87
| Some (`Str i )->
@@ -97,44 +93,34 @@ let get_arg_type ~nolabel optional
97
93
end
98
94
else (* ([`a|`b] [@bs.string]) *)
99
95
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 ->
103
98
begin match ptyp_desc with
104
99
| 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
112
102
| _ ->
113
103
Bs_syntaxerr. err ptyp.ptyp_loc Invalid_bs_string_type
114
104
end
115
- | ( `Ignore, ptyp_attributes ) ->
116
- ( Ignore , {ptyp with ptyp_attributes})
117
- | ( `Int , ptyp_attributes ) ->
105
+ | `Ignore ->
106
+ Ignore
107
+ | `Int ->
118
108
begin match ptyp_desc with
119
109
| Ptyp_variant ( row_fields , Closed, None) ->
120
110
let int_lists =
121
111
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
126
113
| _ -> Bs_syntaxerr. err ptyp.ptyp_loc Invalid_bs_int_type
127
114
end
128
- | (`Unwrap, ptyp_attributes ) ->
129
-
115
+ | `Unwrap ->
130
116
begin match ptyp_desc with
131
- | ( Ptyp_variant (row_fields, Closed , _) as ptyp_desc )
117
+ | Ptyp_variant (row_fields, Closed , _)
132
118
when variant_can_bs_unwrap_fields row_fields ->
133
- Unwrap , {ptyp with ptyp_desc; ptyp_attributes}
119
+ Unwrap
134
120
| _ ->
135
121
Bs_syntaxerr. err ptyp.ptyp_loc Invalid_bs_unwrap_type
136
122
end
137
- | ( `Uncurry opt_arity , ptyp_attributes ) ->
123
+ | `Uncurry opt_arity ->
138
124
let real_arity = Ast_core_type. get_uncurry_arity ptyp in
139
125
(begin match opt_arity, real_arity with
140
126
| Some arity , `Not_function ->
@@ -147,9 +133,8 @@ let get_arg_type ~nolabel optional
147
133
if n <> arity then
148
134
Bs_syntaxerr. err ptyp.ptyp_loc (Inconsistent_arity (arity,n))
149
135
else Fn_uncurry_arity arity
150
-
151
- end , {ptyp with ptyp_attributes})
152
- | (`Nothing, ptyp_attributes ) ->
136
+ end )
137
+ | `Nothing ->
153
138
begin match ptyp_desc with
154
139
| Ptyp_constr ({txt = Lident " unit" ; _}, [] )
155
140
-> if nolabel then Extern_unit else Nothing
@@ -160,7 +145,7 @@ let get_arg_type ~nolabel optional
160
145
Nothing
161
146
| _ ->
162
147
Nothing
163
- end , ptyp
148
+ end ) , ptyp
164
149
165
150
166
151
0 commit comments