Switch on an option of an untagged variant with an `@as(undefined)` case takes the wrong arm for `Some` of that case
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 28/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript, ocaml
- 領域
- compilers
研究方向
Start with rejects_nested_some in compiler/ml/matching.ml, which decides whether a pattern reads the payload with Pval_from_option_not_nest and skips unwrapping the nested Some box. Reproduce with the g(Some(U)) snippet from the issue and inspect the compiled JavaScript for the typeof and === undefined tests. Done when Some(U) reaches the Some(_) arm and prints SU, with the constant and runtime-built cases agreeing.
由索引模型根據 Issue 內容生成。
描述
Found by differential semantic drift analysis from b123b7c3 to c10223e8.
What is broken
@unboxed type t = @as(undefined) U | S(string) | I(int)
let g = (x: option<t>) =>
switch x {
| None => "None"
| Some(S(_)) => "SS"
| Some(I(_)) => "SI"
| Some(_) => "SU"
}
Console.log(g(Some(U)))
Expected SU. At c10223e8 it prints SI; at b123b7c3 it printed None (the construction bug fixed by #9008). A Some(U) built at run time (let h = v => g(Some(v)), h(U)) prints SI at both commits, so the match bug predates the range; #9008 makes constant values reach it too. Matches that name Some(U) explicitly, and tagged variants, are correct.
The compiled g tests x !== undefined, then x === undefined, then typeof x === "string", and otherwise returns "SI", without unwrapping the nested-Some box first: the boxed Some(U) fails the first two tests and lands in the last case.
rejects_nested_some returns true for _ and for untagged payload patterns, so the match reads the payload with Pval_from_option_not_nest, which skips unwrapping.
Possible cause (speculation only)
rejects_nested_some assumes that each pattern rejects the box on its own test, but the untagged dispatch decides the last remaining case by elimination, without a test of its own.
🤖 Generated with Claude Code
- 主要語言
- OCaml
- 星號
- 7.5k
- 分支
- 484
- 平均合併
- 17 小時 2 分鐘
- 30 天內合併 PR
- 249
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
rescript-lang/rescript 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
rescript-lang/rescript#9182 ·
維護者通常 1 天內回覆
-
Issues from differential semantic drift analysis (b123b7c3 to c10223e8)可能已有人在做 @cknitt 今天認領。 未關閉
rescript-lang/rescript#9186 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 38/100
rescript-lang/rescript#9185 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 55/100
rescript-lang/rescript#9183 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 35/100
rescript-lang/rescript#9181 ·
維護者通常 1 天內回覆
查看 rescript-lang/rescript 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 90/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 88/100
AeneasVerif/aeneas#1534 ·
維護者通常 1 天內回覆
-
arrays asr pass bug ICE intrinsic medium priority
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
mlir
難度 2/5 1-3 小時 新手友好度 62/100
llvm/llvm-project#238303 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆