Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Integer range patterns ending at 2147483647 generate incorrect JavaScript

Đang mở
#8,716 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
70/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, ocaml
Lĩnh vực
compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
OCaml
Star
7.5k
Fork
485
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
65

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rescript-lang/rescript

Tất cả issue của rescript-lang/rescript

Issue tương tự

Thêm issue về Compilers

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.