@@ -57,9 +57,6 @@ let mark_used_bs_attribute ((x,_) : Parsetree.attribute) =
57
57
if not x.loc.loc_ghost then
58
58
Hash_set_poly. add used_attributes x
59
59
60
- let dummy_unused_attribute : Warnings.t = (Bs_unused_attribute " " )
61
-
62
-
63
60
64
61
let warn_unused_attribute
65
62
(({txt; loc} as sloc , _ ) : Parsetree. attribute ) =
@@ -81,6 +78,38 @@ let warn_discarded_unused_attributes (attrs : Parsetree.attributes) =
81
78
82
79
type iterator = Ast_iterator .iterator
83
80
let default_iterator = Ast_iterator. default_iterator
81
+
82
+ let check_constant loc kind (const : Parsetree.constant ) =
83
+ match const with
84
+ | Pconst_string
85
+ (_, Some s) ->
86
+ begin match kind with
87
+ | `expr ->
88
+ (if Ast_utf8_string_interp. is_unescaped s then
89
+ Bs_warnings. error_unescaped_delimiter loc s)
90
+ | `pat ->
91
+ if s = " j" then
92
+ Location. raise_errorf ~loc " Unicode string is not allowed in pattern match"
93
+ end
94
+ | Pconst_integer (s ,None) ->
95
+ (* range check using int32
96
+ It is better to give a warning instead of error to avoid make people unhappy.
97
+ It also has restrictions in which platform bsc is running on since it will
98
+ affect int ranges
99
+ *)
100
+ (
101
+ try
102
+ ignore (
103
+ if String. length s = 0 || s.[0 ] = '-' then
104
+ Int32. of_string s
105
+ else Int32. of_string (" -" ^ s))
106
+ with _ ->
107
+ Bs_warnings. warn_literal_overflow loc
108
+ )
109
+ | Pconst_integer (_, Some 'n' )
110
+ -> Location. raise_errorf ~loc " literal with `n` suffix is not supported"
111
+ | _ -> ()
112
+
84
113
(* Note we only used Bs_ast_iterator here, we can reuse compiler-libs instead of
85
114
rolling our own*)
86
115
let emit_external_warnings : iterator =
@@ -96,27 +125,8 @@ let emit_external_warnings : iterator=
96
125
| _ -> default_iterator.structure_item self str_item
97
126
);
98
127
expr = (fun self a ->
99
- match a.pexp_desc with
100
- | Pexp_constant (
101
- Pconst_string
102
- (_, Some s))
103
- when Ast_utf8_string_interp. is_unescaped s ->
104
- Bs_warnings. error_unescaped_delimiter a.pexp_loc s
105
- | Pexp_constant (Pconst_integer(s ,None)) ->
106
- (* range check using int32
107
- It is better to give a warning instead of error to avoid make people unhappy.
108
- It also has restrictions in which platform bsc is running on since it will
109
- affect int ranges
110
- *)
111
- (
112
- try
113
- ignore (
114
- if String. length s = 0 || s.[0 ] = '-' then
115
- Int32. of_string s
116
- else Int32. of_string (" -" ^ s))
117
- with _ ->
118
- Bs_warnings. warn_literal_overflow a.pexp_loc
119
- )
128
+ match a.pexp_desc with
129
+ | Pexp_constant (const ) -> check_constant a.pexp_loc `expr const
120
130
| _ -> default_iterator.expr self a
121
131
);
122
132
label_declaration = (fun self lbl ->
@@ -156,14 +166,12 @@ let emit_external_warnings : iterator=
156
166
| _ ->
157
167
default_iterator.value_description self v
158
168
);
159
- pat = begin fun self (pat : Parsetree.pattern ) ->
160
- match pat.ppat_desc with
161
- | Ppat_constant (
162
- Pconst_string
163
- (_, Some " j" )) ->
164
- Location. raise_errorf ~loc: pat.ppat_loc " Unicode string is not allowed in pattern match"
169
+ pat = begin fun self (pat : Parsetree.pattern ) ->
170
+ match pat.ppat_desc with
171
+ | Ppat_constant (constant ) ->
172
+ check_constant pat.ppat_loc `pat constant
165
173
| _ -> default_iterator.pat self pat
166
- end
174
+ end
167
175
}
168
176
169
177
let rec iter_warnings_on_stru (stru : Parsetree.structure ) =
@@ -190,9 +198,7 @@ let rec iter_warnings_on_sigi (stru : Parsetree.signature) =
190
198
191
199
192
200
let emit_external_warnings_on_structure (stru : Parsetree.structure ) =
193
- if Warnings. is_active dummy_unused_attribute then
194
- emit_external_warnings.structure emit_external_warnings stru
201
+ emit_external_warnings.structure emit_external_warnings stru
195
202
196
203
let emit_external_warnings_on_signature (sigi : Parsetree.signature ) =
197
- if Warnings. is_active dummy_unused_attribute then
198
- emit_external_warnings.signature emit_external_warnings sigi
204
+ emit_external_warnings.signature emit_external_warnings sigi
0 commit comments