Integer range patterns ending at 2147483647 generate incorrect JavaScript
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 70/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- javascript, ocaml
- 領域
- compilers
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- OCaml
- スター
- 7.5k
- フォーク
- 485
- 平均マージ
- 1日 3時間
- マージ済み PR(30日)
- 65
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rescript-lang/rescript のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
rescript-lang/rescript#8713 ·
メンテナーはふだん 1 日以内に返信
-
A regex literal that starts a statement is parsed as division, and the formatter removes the parentheses that prevent it対応中かも @fhammerschmidt が 2 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
rescript-lang/rescript#8688 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bsc crashes with `Fatal error: exception Not_found` on `Some(x)` when the type of `x` comes from a transitive dependency対応中かも @fhammerschmidt が 2 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
rescript-lang/rescript#8687 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
rescript-lang/rescript#8659 · コメント 2 件 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
rescript-lang/rescript#8647 ·
メンテナーはふだん 1 日以内に返信
rescript-lang/rescript の issue をすべて見る