Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Integer range patterns on record fields match values below the range

未關閉
#8,713 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

已經有一個關聯 PR 被合併了。

  • #8714 來自 @mvaled —— 已合併

評估

難度
3/5
預估耗時
1-2 天
新手友好度
76/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
javascript, ocaml
領域
compilers

研究方向

Start in Js_exp_make.is_out and compare its fallback handling with commit 6d78c5832781165685b45bb2092d8edf170b75ae, where to_uint32 was removed. Reproduce the record-field range example and inspect the generated JavaScript. Done means values below 502 no longer match the 502–504 range while the valid range still does.

由索引模型根據 Issue 內容生成。

描述

Reported in the forum: https://forum.rescript-lang.org/t/potential-bug-in-code-generation-of-subpattern-of-integers-httperror-status-502-503-504-rescript-12-and-13/7598

Matching a contiguous range of integers on a value that is not a plain variable (e.g. a record field) generates a signed comparison, so every value below the range also matches.

type response = {status: int}
let isRetriable = error =>
  switch error {
  | {status: 502 | 503 | 504} => true
  | _ => false
  }

ReScript 12 and 13 (alpha) generate:

function isRetriable(error) {
  return (error.status - 502 | 0) <= 2;
}

which returns true for 404, 500, 501, etc. ReScript 10 and 11 generated (error.status - 502 >>> 0) <= 2, which is correct.

A bare switch x { | 502 | 503 | 504 => ... } is not affected; it compiles to !(x > 504 || x < 502).

The unsigned conversion in the fallback case of Js_exp_make.is_out was lost in https://github.com/rescript-lang/rescript/commit/6d78c5832781165685b45bb2092d8edf170b75ae when to_uint32 was removed.

主要語言
ReScript
星號
7.5k
分支
483
平均合併
1 天 3 小時
30 天內合併 PR
136

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

rescript-lang/rescript 的其他 Issue

查看 rescript-lang/rescript 的全部 Issue

相似的 Issue

更多 Compilers Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。