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.
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.xcode both before and after the change in #8714.Generated JavaScript, identical before and after #8714:
Expected and observed results:
The generated condition requires the same integer to be at least
2147483645and less than-2147483648, so it can never succeed. This appears to be overflow when converting the exclusive upper bound2147483647 + 1into 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.