Integer range patterns ending at 2147483647 generate incorrect JavaScript
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 70/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- javascript, ocaml
- Domain
- compilers
Research direction
Use the maintenance/12.x compiler with the supplied ReScript switch, first inspecting the generated JavaScript for the integer-range condition. Reproduce the boundary cases and compare the compiler's handling of the exclusive upper bound with the signed 32-bit limit. Done means the generated check accepts 2147483645–2147483647 and rejects 2147483644, including the other listed switch shapes.
Written by the indexing model from the issue text.
Description
An integer or-pattern ending at 2147483647 (the maximum signed 32-bit integer) compiles to an impossible bound check and rejects values that should match.
Reproduced with the ReScript 12.3.1 compiler on macOS arm64, using the maintenance/12.x code both before and after the change in #8714.
type response = {status: int}
let inRange = (x: response) =>
switch x {
| {status: 2147483645 | 2147483646 | 2147483647} => true
| _ => false
}
Generated JavaScript, identical before and after #8714:
function inRange(x) {
let match = x.status;
if (match >= 2147483645) {
return match < -2147483648;
} else {
return false;
}
}
Expected and observed results:
| Input status | Expected | Actual |
|---|---|---|
| 2147483644 | false | false |
| 2147483645 | true | false |
| 2147483646 | true | false |
| 2147483647 | true | false |
The generated condition requires the same integer to be at least 2147483645 and less than -2147483648, so it can never succeed. This appears to be overflow when converting the exclusive upper bound 2147483647 + 1 into a 32-bit integer literal.
The same failure also reproduces with a plain integer switch, nested records, tuples, variant payloads, arrays, and switches on function-call results.
This was found while reviewing #8714 and is a separate, pre-existing bug: the unsigned-range fix in that PR neither introduces nor fixes it.
- Dominant language
- OCaml
- Stars
- 7.5k
- Forks
- 484
- Avg merge
- 19h 46m
- Merged PRs (30d)
- 81
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rescript-lang/rescript
-
Difficulty 3/5 Half a day Newbie friendliness 58/100
rescript-lang/rescript#8757 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 40/100
rescript-lang/rescript#8753 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 22/100
rescript-lang/rescript#8733 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
rescript-lang/rescript#8727 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
rescript-lang/rescript#8726 ·
Maintainers usually reply within 1 day
All issues in rescript-lang/rescript
Similar issues
-
bug derived types format I/O medium priority semantics
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
lexer: a lone `"` at the end of a file panics instead of reporting an errorPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
bytecodealliance/wasm-tools#2768 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
antlr/grammars-v4#5035 ·
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day