File tree Expand file tree Collapse file tree 9 files changed +57
-2
lines changed Expand file tree Collapse file tree 9 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,12 @@ let warn_missing_primitive loc txt =
87
87
Format. pp_print_flush warning_formatter ()
88
88
end
89
89
90
-
90
+ let warn_literal_overflow loc =
91
+ begin
92
+ print_string_warning loc
93
+ " Integer literal exceeds the range of representable integers of type int" ;
94
+ Format. pp_print_flush warning_formatter ()
95
+ end
91
96
92
97
let error_unescaped_delimiter loc txt =
93
98
raise (Error (loc, Uninterpreted_delimiters txt))
Original file line number Diff line number Diff line change @@ -31,5 +31,7 @@ val prerr_bs_ffi_warning : Location.t -> t -> unit
31
31
32
32
val warn_missing_primitive : Location .t -> string -> unit
33
33
34
+ val warn_literal_overflow : Location .t -> unit
35
+
34
36
val error_unescaped_delimiter :
35
37
Location .t -> string -> unit
Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ let emit_external_warnings : iterator=
86
86
default_iterator with
87
87
attribute = (fun _ attr -> warn_unused_attribute attr);
88
88
expr = (fun self a ->
89
- match a.Parsetree. pexp_desc with
89
+ match a.pexp_desc with
90
90
| Pexp_constant (
91
91
#if OCAML_VERSION =~ " >4.03.0" then
92
92
Pconst_string
@@ -96,6 +96,23 @@ let emit_external_warnings : iterator=
96
96
(_, Some s))
97
97
when Ast_utf8_string_interp. is_unescaped s ->
98
98
Bs_warnings. error_unescaped_delimiter a.pexp_loc s
99
+ #if OCAML_VERSION =~ " >4.03.0" then
100
+ | Pexp_constant (Pconst_integer(s ,None)) ->
101
+ (* range check using int32
102
+ It is better to give a warning instead of error to avoid make people unhappy.
103
+ It also has restrictions in which platform bsc is running on since it will
104
+ affect int ranges
105
+ *)
106
+ (
107
+ try
108
+ ignore (
109
+ if String. length s = 0 || s.[0 ] = '-' then
110
+ Int32. of_string s
111
+ else Int32. of_string (" -" ^ s))
112
+ with _ ->
113
+ Bs_warnings. warn_literal_overflow a.pexp_loc
114
+ )
115
+ #end
99
116
| _ -> default_iterator.expr self a
100
117
);
101
118
value_description =
Original file line number Diff line number Diff line change @@ -269,6 +269,7 @@ OTHERS := test_literals a test_ari test_export2 test_internalOO test_obj_simple_
269
269
fun_pattern_match\
270
270
gpr_3142_test\
271
271
gpr_3154_test\
272
+ gpr_373_test\
272
273
ocaml_typedtree_test
273
274
# ocaml_typedtree_test is not cross version due to camlinternalFormat
274
275
# bs_uncurry_test
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+
4
+ var overflow_dec_i32_number = 272872590 ;
5
+
6
+ var overflow_dec_i32_number_2 = 0 ;
7
+
8
+ var not_overflow_dec_i32_number_3 = - 1 ;
9
+
10
+ var overflow_hex_i32_number = - 1 ;
11
+
12
+ exports . overflow_dec_i32_number = overflow_dec_i32_number ;
13
+ exports . overflow_dec_i32_number_2 = overflow_dec_i32_number_2 ;
14
+ exports . not_overflow_dec_i32_number_3 = not_overflow_dec_i32_number_3 ;
15
+ exports . overflow_hex_i32_number = overflow_hex_i32_number ;
16
+ /* No side effect */
Original file line number Diff line number Diff line change
1
+
2
+
3
+ let overflow_dec_i32_number = 949_460_645_006
4
+
5
+ let overflow_dec_i32_number_2 = 4611686018427387904 (* max_int + 1*)
6
+
7
+ let overflow_dec_i32_number_2 = 4611686018427387904
8
+
9
+ let not_overflow_dec_i32_number_3 = 0xffff_ffff
10
+ let overflow_hex_i32_number = 0xffff_ffffl
Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ if (exit === 1) {
80
80
"common" ,
81
81
"super_errors" ,
82
82
"." ,
83
+ "stubs" ,
83
84
"stdlib-406"
84
85
] ) ;
85
86
exec ( /* () */ 0 ) ;
Original file line number Diff line number Diff line change @@ -57,6 +57,8 @@ let () =
57
57
" common" ;
58
58
" super_errors" ;
59
59
" ." ;
60
+ " stubs" ;
61
+
60
62
" stdlib-406" ; (* evolve *)
61
63
|];
62
64
Original file line number Diff line number Diff line change @@ -260,6 +260,7 @@ if (exit === 1) {
260
260
"common" ,
261
261
"super_errors" ,
262
262
"." ,
263
+ "stubs" ,
263
264
"stdlib-406"
264
265
] ) ;
265
266
exec ( /* () */ 0 ) ;
You can’t perform that action at this time.
0 commit comments