Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Integer range patterns ending at 2147483647 generate incorrect JavaScript

オープン
#8,716 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 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

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rescript-lang/rescript のほかの issue

rescript-lang/rescript の issue をすべて見る

似ている issue

Compilers の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。