Skip to content

Fix #373 #333 in 4.06 #3158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion jscomp/common/bs_warnings.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ let warn_missing_primitive loc txt =
Format.pp_print_flush warning_formatter ()
end


let warn_literal_overflow loc =
begin
print_string_warning loc
"Integer literal exceeds the range of representable integers of type int";
Format.pp_print_flush warning_formatter ()
end

let error_unescaped_delimiter loc txt =
raise (Error(loc, Uninterpreted_delimiters txt))
Expand Down
2 changes: 2 additions & 0 deletions jscomp/common/bs_warnings.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ val prerr_bs_ffi_warning : Location.t -> t -> unit

val warn_missing_primitive : Location.t -> string -> unit

val warn_literal_overflow : Location.t -> unit

val error_unescaped_delimiter :
Location.t -> string -> unit
19 changes: 18 additions & 1 deletion jscomp/syntax/bs_ast_invariant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ let emit_external_warnings : iterator=
default_iterator with
attribute = (fun _ attr -> warn_unused_attribute attr);
expr = (fun self a ->
match a.Parsetree.pexp_desc with
match a.pexp_desc with
| Pexp_constant (
#if OCAML_VERSION =~ ">4.03.0" then
Pconst_string
Expand All @@ -96,6 +96,23 @@ let emit_external_warnings : iterator=
(_, Some s))
when Ast_utf8_string_interp.is_unescaped s ->
Bs_warnings.error_unescaped_delimiter a.pexp_loc s
#if OCAML_VERSION =~ ">4.03.0" then
| Pexp_constant(Pconst_integer(s,None)) ->
(* range check using int32
It is better to give a warning instead of error to avoid make people unhappy.
It also has restrictions in which platform bsc is running on since it will
affect int ranges
*)
(
try
ignore (
if String.length s = 0 || s.[0] = '-' then
Int32.of_string s
else Int32.of_string ("-" ^ s))
with _ ->
Bs_warnings.warn_literal_overflow a.pexp_loc
)
#end
| _ -> default_iterator.expr self a
);
value_description =
Expand Down
1 change: 1 addition & 0 deletions jscomp/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ OTHERS := test_literals a test_ari test_export2 test_internalOO test_obj_simple_
fun_pattern_match\
gpr_3142_test\
gpr_3154_test\
gpr_373_test\
ocaml_typedtree_test
# ocaml_typedtree_test is not cross version due to camlinternalFormat
# bs_uncurry_test
Expand Down
16 changes: 16 additions & 0 deletions jscomp/test/gpr_373_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';


var overflow_dec_i32_number = 272872590;

var overflow_dec_i32_number_2 = 0;

var not_overflow_dec_i32_number_3 = -1;

var overflow_hex_i32_number = -1;

exports.overflow_dec_i32_number = overflow_dec_i32_number;
exports.overflow_dec_i32_number_2 = overflow_dec_i32_number_2;
exports.not_overflow_dec_i32_number_3 = not_overflow_dec_i32_number_3;
exports.overflow_hex_i32_number = overflow_hex_i32_number;
/* No side effect */
10 changes: 10 additions & 0 deletions jscomp/test/gpr_373_test.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


let overflow_dec_i32_number = 949_460_645_006

let overflow_dec_i32_number_2 = 4611686018427387904 (* max_int + 1*)

let overflow_dec_i32_number_2 = 4611686018427387904

let not_overflow_dec_i32_number_3 = 0xffff_ffff
let overflow_hex_i32_number = 0xffff_ffffl
1 change: 1 addition & 0 deletions jscomp/xwatcher/xwatcher_current.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ if (exit === 1) {
"common",
"super_errors",
".",
"stubs",
"stdlib-406"
]);
exec(/* () */0);
Expand Down
2 changes: 2 additions & 0 deletions jscomp/xwatcher/xwatcher_current.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ let () =
"common";
"super_errors";
".";
"stubs";

"stdlib-406" ; (* evolve *)
|];

Expand Down
1 change: 1 addition & 0 deletions scripts/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ if (exit === 1) {
"common",
"super_errors",
".",
"stubs",
"stdlib-406"
]);
exec(/* () */0);
Expand Down