Skip to content

Commit 3931bfa

Browse files
committed
Fix issue with integer overflow check
Fixes #6025
1 parent 7dc4441 commit 3931bfa

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ These are only breaking changes for unformatted code.
7272
- Fix location issue for the treatment of `async` functions where hovering on the body with a type error would show `'a => promise<'a>` everywhere https://github.com/rescript-lang/rescript-compiler/pull/6012
7373
- Fix formatting of `switch` expressions that contain brace `cases` inside https://github.com/rescript-lang/rescript-compiler/pull/6015
7474
- Support `@gentype.import` as an alias to `@genType.import` in the compiler https://github.com/rescript-lang/rescript-compiler/pull/6020
75+
- Fix issue with integer overflow check
7576

7677
#### :nail_care: Polish
7778

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
Warning number 107
3+
/.../fixtures/intoverflow.res:2:15-27
4+
5+
1 │ let v1: int = 2_147_483_647
6+
2 │ let v2: int = 2_147_483_648
7+
3 │ let v3: int = 2_147_483_649
8+
4 │ let v4: int = -2_147_483_647
9+
10+
Integer literal exceeds the range of representable integers of type int
11+
12+
13+
Warning number 107
14+
/.../fixtures/intoverflow.res:3:15-27
15+
16+
1 │ let v1: int = 2_147_483_647
17+
2 │ let v2: int = 2_147_483_648
18+
3 │ let v3: int = 2_147_483_649
19+
4 │ let v4: int = -2_147_483_647
20+
5 │ let v5: int = -2_147_483_648
21+
22+
Integer literal exceeds the range of representable integers of type int
23+
24+
25+
Warning number 107
26+
/.../fixtures/intoverflow.res:6:16-28
27+
28+
4 │ let v4: int = -2_147_483_647
29+
5 │ let v5: int = -2_147_483_648
30+
6 │ let v6: int = -2_147_483_649
31+
7 │
32+
33+
Integer literal exceeds the range of representable integers of type int
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let v1: int = 2_147_483_647
2+
let v2: int = 2_147_483_648
3+
let v3: int = 2_147_483_649
4+
let v4: int = -2_147_483_647
5+
let v5: int = -2_147_483_648
6+
let v6: int = -2_147_483_649

jscomp/frontend/bs_ast_invariant.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ let check_constant loc kind (const : Parsetree.constant) =
8989
affect int ranges
9090
*)
9191
try
92-
ignore
93-
(if String.length s = 0 || s.[0] = '-' then Int32.of_string s
94-
else Int32.of_string ("-" ^ s))
92+
ignore @@ Int32.of_string s
9593
with _ -> Bs_warnings.warn_literal_overflow loc)
9694
| Pconst_integer (_, Some 'n') ->
9795
Location.raise_errorf ~loc "literal with `n` suffix is not supported"

0 commit comments

Comments
 (0)