Skip to content

Commit 60b5e1a

Browse files
committed
refactor
1 parent fe0388b commit 60b5e1a

File tree

3 files changed

+21
-31
lines changed

3 files changed

+21
-31
lines changed

jscomp/frontend/ast_core_type.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,26 @@ open Ast_helper
5656
| _ -> result in
5757
aux ty *)
5858

59+
let is_builtin_rank0_type txt =
60+
match txt with
61+
| "int"
62+
| "char"
63+
| "bytes"
64+
| "float"
65+
| "bool"
66+
| "unit"
67+
| "exn"
68+
| "int32"
69+
| "int64"
70+
| "string" -> true
71+
| _ -> false
72+
5973
let is_unit (ty : t ) =
6074
match ty.ptyp_desc with
6175
| Ptyp_constr({txt =Lident "unit"}, []) -> true
6276
| _ -> false
6377

78+
6479
(* let is_array (ty : t) =
6580
match ty.ptyp_desc with
6681
| Ptyp_constr({txt =Lident "array"}, [_]) -> true

jscomp/frontend/ast_core_type.mli

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ type t = Parsetree.core_type
2929

3030
val lift_option_type : t -> t
3131

32-
(* val replace_result : t -> t -> t *)
33-
34-
(* val opt_arrow: Location.t -> string -> t -> t -> t *)
35-
3632
val is_unit : t -> bool
37-
(* val is_array : t -> bool *)
3833

34+
val is_builtin_rank0_type :
35+
string -> bool
3936

4037
(** return a function type
4138
[from_labels ~loc tyvars labels]
@@ -52,11 +49,6 @@ val make_obj :
5249

5350
val is_user_option : t -> bool
5451

55-
(* val is_user_bool : t -> bool
56-
57-
val is_user_int : t -> bool *)
58-
59-
6052

6153
(**
6254
returns 0 when it can not tell arity from the syntax

jscomp/frontend/bs_ast_invariant.ml

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -117,27 +117,10 @@ let emit_external_warnings : iterator=
117117
super with
118118
type_declaration = (fun self ptyp ->
119119
let txt = ptyp.ptype_name.txt in
120-
(match txt with
121-
| "int"
122-
| "char"
123-
| "bytes"
124-
| "float"
125-
| "bool"
126-
| "unit"
127-
| "exn"
128-
| "int32"
129-
| "int64"
130-
| "string"
131-
(* not adding parametric types yet
132-
| "array"
133-
| "list"
134-
| "option"
135-
*)
136-
->
137-
Location.raise_errorf ~loc:ptyp.ptype_loc
138-
"built-in type `%s` can not be redefined " txt
139-
| _ -> ()
140-
);
120+
if Ast_core_type.is_builtin_rank0_type txt then
121+
Location.raise_errorf ~loc:ptyp.ptype_loc
122+
"built-in type `%s` can not be redefined " txt
123+
;
141124
super.type_declaration self ptyp
142125
);
143126
attribute = (fun _ attr -> warn_unused_attribute attr);

0 commit comments

Comments
 (0)