Skip to content

Commit c9a44ee

Browse files
committed
Move detection of more builtin attributes to new module.
1 parent b8dccca commit c9a44ee

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

parsing/builtin_attributes.ml

+15
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,18 @@ let with_warning_attribute attrs f =
156156
with exn ->
157157
warning_leave_scope ();
158158
raise exn
159+
160+
161+
let warn_on_literal_pattern =
162+
List.exists
163+
(function
164+
| ({txt="ocaml.warn_on_literal_pattern"|"warn_on_literal_pattern"; _}, _) -> true
165+
| _ -> false
166+
)
167+
168+
let explicit_arity =
169+
List.exists
170+
(function
171+
| ({txt="ocaml.explicit_arity"|"explicit_arity"; _}, _) -> true
172+
| _ -> false
173+
)

parsing/builtin_attributes.mli

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
ocaml.ppwarning
1818
ocaml.warning
1919
ocaml.warnerror
20-
20+
ocaml.explicit_arity (for camlp4/camlp5)
21+
ocaml.warn_on_literal_pattern
2122
*)
2223

2324

@@ -34,3 +35,6 @@ val warning_attribute: Parsetree.attributes -> unit
3435
val with_warning_attribute: Parsetree.attributes -> (unit -> 'a) -> 'a
3536

3637
val emit_external_warnings: Ast_mapper.mapper
38+
39+
val warn_on_literal_pattern: Parsetree.attributes -> bool
40+
val explicit_arity: Parsetree.attributes -> bool

typing/typecore.ml

+8-19
Original file line numberDiff line numberDiff line change
@@ -305,20 +305,6 @@ let extract_label_names sexp env ty =
305305
with Not_found ->
306306
assert false
307307

308-
let explicit_arity =
309-
List.exists
310-
(function
311-
| ({txt="ocaml.explicit_arity"|"explicit_arity"; _}, _) -> true
312-
| _ -> false
313-
)
314-
315-
let warn_on_literal_pattern =
316-
List.exists
317-
(function
318-
| ({txt="ocaml.warn_on_literal_pattern"|"warn_on_literal_pattern"; _}, _) -> true
319-
| _ -> false
320-
)
321-
322308
(* Typing of patterns *)
323309

324310
(* unification inside type_pat*)
@@ -1115,7 +1101,8 @@ let rec type_pat ~constrs ~labels ~no_existentials ~mode ~explode ~env
11151101
match sarg with
11161102
None -> []
11171103
| Some {ppat_desc = Ppat_tuple spl} when
1118-
constr.cstr_arity > 1 || explicit_arity sp.ppat_attributes
1104+
constr.cstr_arity > 1 ||
1105+
Builtin_attributes.explicit_arity sp.ppat_attributes
11191106
-> spl
11201107
| Some({ppat_desc = Ppat_any} as sp) when constr.cstr_arity <> 1 ->
11211108
if constr.cstr_arity = 0 then
@@ -1124,9 +1111,11 @@ let rec type_pat ~constrs ~labels ~no_existentials ~mode ~explode ~env
11241111
replicate_list sp constr.cstr_arity
11251112
| Some sp -> [sp] in
11261113
begin match sargs with
1127-
| [{ppat_desc = Ppat_constant _} as sp] when warn_on_literal_pattern constr.cstr_attributes ->
1128-
Location.prerr_warning sp.ppat_loc
1129-
Warnings.Fragile_literal_pattern
1114+
| [{ppat_desc = Ppat_constant _} as sp]
1115+
when Builtin_attributes.warn_on_literal_pattern
1116+
constr.cstr_attributes ->
1117+
Location.prerr_warning sp.ppat_loc
1118+
Warnings.Fragile_literal_pattern
11301119
| _ -> ()
11311120
end;
11321121
if List.length sargs <> constr.cstr_arity then
@@ -3557,7 +3546,7 @@ and type_construct env loc lid sarg ty_expected attrs =
35573546
match sarg with
35583547
None -> []
35593548
| Some {pexp_desc = Pexp_tuple sel} when
3560-
constr.cstr_arity > 1 || explicit_arity attrs
3549+
constr.cstr_arity > 1 || Builtin_attributes.explicit_arity attrs
35613550
-> sel
35623551
| Some se -> [se] in
35633552
if List.length sargs <> constr.cstr_arity then

0 commit comments

Comments
 (0)