Skip to content

Fix issue with integer overflow check #6028

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 2 commits into from
Mar 3, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ These are only breaking changes for unformatted code.
- 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
- Fix formatting of `switch` expressions that contain brace `cases` inside https://github.com/rescript-lang/rescript-compiler/pull/6015
- Support `@gentype.import` as an alias to `@genType.import` in the compiler https://github.com/rescript-lang/rescript-compiler/pull/6020
- Fix issue with integer overflow check https://github.com/rescript-lang/rescript-compiler/pull/6028

#### :nail_care: Polish

Expand Down
57 changes: 57 additions & 0 deletions jscomp/build_tests/super_errors/expected/intoverflow.res.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

Warning number 107
/.../fixtures/intoverflow.res:2:15-27

1 │ let v1: int = 2_147_483_647 // max int
2 │ let v2: int = 2_147_483_648 // overflow
3 │ let v3: int = 2_147_483_649 // overflow
4 │ let v4: int = -2_147_483_647

Integer literal exceeds the range of representable integers of type int


Warning number 107
/.../fixtures/intoverflow.res:3:15-27

1 │ let v1: int = 2_147_483_647 // max int
2 │ let v2: int = 2_147_483_648 // overflow
3 │ let v3: int = 2_147_483_649 // overflow
4 │ let v4: int = -2_147_483_647
5 │ let v5: int = -2_147_483_648 // min int

Integer literal exceeds the range of representable integers of type int


Warning number 107
/.../fixtures/intoverflow.res:6:16-28

4 │ let v4: int = -2_147_483_647
5 │ let v5: int = -2_147_483_648 // min int
6 │ let v6: int = -2_147_483_649 // underflow
7 │
8 │ // hex

Integer literal exceeds the range of representable integers of type int


Warning number 107
/.../fixtures/intoverflow.res:11:14-26

9 │ let v7: int = 0xFFFF_FFFF // -1
10 │ let v8: int = -0xFFFF_FFFF // 1
11 │ let v9:int = 0x1_0000_0000 // overflow
12 │ let v10:int = -0x1_0000_0000 // underflow
13 │

Integer literal exceeds the range of representable integers of type int


Warning number 107
/.../fixtures/intoverflow.res:12:16-28

10 │ let v8: int = -0xFFFF_FFFF // 1
11 │ let v9:int = 0x1_0000_0000 // overflow
12 │ let v10:int = -0x1_0000_0000 // underflow
13 │

Integer literal exceeds the range of representable integers of type int
12 changes: 12 additions & 0 deletions jscomp/build_tests/super_errors/fixtures/intoverflow.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let v1: int = 2_147_483_647 // max int
let v2: int = 2_147_483_648 // overflow
let v3: int = 2_147_483_649 // overflow
let v4: int = -2_147_483_647
let v5: int = -2_147_483_648 // min int
let v6: int = -2_147_483_649 // underflow

// hex
let v7: int = 0xFFFF_FFFF // -1
let v8: int = -0xFFFF_FFFF // 1
let v9:int = 0x1_0000_0000 // overflow
let v10:int = -0x1_0000_0000 // underflow
4 changes: 1 addition & 3 deletions jscomp/frontend/bs_ast_invariant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ let check_constant loc kind (const : Parsetree.constant) =
affect int ranges
*)
try
ignore
(if String.length s = 0 || s.[0] = '-' then Int32.of_string s
else Int32.of_string ("-" ^ s))
ignore @@ Int32.of_string s
with _ -> Bs_warnings.warn_literal_overflow loc)
| Pconst_integer (_, Some 'n') ->
Location.raise_errorf ~loc "literal with `n` suffix is not supported"
Expand Down