Untagged variant switch with a default arm matches instances and literals in the wrong case
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 1-2 天
- 新手友好度
- 55/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript, ocaml
- 領域
- compilers
研究方向
Start with compiler/ml/lam_compile.ml, especially compile_untagged_cases and compile_general_cases, then compare the behavior with rules 7 and 8 in compiler/ml/UntaggedVariants.md. Run or add compiler cases for the instance and literal examples in the issue; done means both produce other for the shown inputs while preserving the documented matching rules.
由索引模型根據 Issue 內容生成。
描述
A switch on an untagged variant with a _ arm can match a value in the wrong case. This happens when the default survives into the untagged dispatch, which takes a variant with several cases; with fewer cases the match compiler expands _ into the remaining cases and the result is correct.
An instance lands in the object case.
@unboxed type t = D(Date.t) | R(RegExp.t) | O({x: int}) | S(string) | I(int) | F(int => int)
@inline(never) let id = (x: t) => x
let f = v => switch v { | O(_) => "O" | S(_) => "S" | _ => "other" }
Console.log(f(id(D(Date.make()))))
function f(v) {
switch (typeof v) {
case "object" :
return "O";
case "string" :
return "S";
default:
return "other";
}
}
Output: O; expected other. The case "object" lacks the !(v instanceof Date) && !(v instanceof RegExp) exclusion that the object check gets elsewhere.
A literal lands in the string case.
@unboxed type t = | @as("lit") Lit | S(string) | I(int) | B(bool) | O({x: int}) | F(int => int)
@inline(never) let id = (x: t) => x
let f = v => switch v { | S(_) => "S" | O(_) => "O" | _ => "other" }
Console.log(f(id(Lit)))
function f(v) {
switch (typeof v) {
case "string" :
return "S";
case "object" :
return "O";
default:
return "other";
}
}
Output: S; expected other. No test for the literal "lit" is emitted before the typeof switch.
Both contradict compiler/ml/UntaggedVariants.md: rule 7 ("A value equal to a literal therefore belongs to the literal's case") and rule 8 ("In both forms a value of an instance case never lands in the object case"). The cause is presumably in lam_compile.ml:compile_untagged_cases / compile_general_cases when the switch keeps a Default and the instance and literal cases it would need to exclude have no arm of their own (not yet confirmed).
- 主要語言
- OCaml
- 星號
- 7.5k
- 分支
- 483
- 平均合併
- 21 小時 8 分鐘
- 30 天內合併 PR
- 183
環境準備
在瀏覽器裡用你自己的 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#8996 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 70/100
rescript-lang/rescript#8997 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 68/100
rescript-lang/rescript#8994 ·
維護者通常 1 天內回覆
-
Issues from differential semantic drift analysis (a7721303 to b123b7c3)可能已有人在做 @cknitt 今天認領。 未關閉
rescript-lang/rescript#8980 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
Doc-comment attributes: editor analysis accepts `@ocaml.doc`/`@ns.doc`, genType and the printer do not可能已有人在做 @cknitt 今天認領。 未關閉
難度 3/5 1-2 天 新手友好度 25/100
rescript-lang/rescript#8978 ·
維護者通常 1 天內回覆
查看 rescript-lang/rescript 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 83/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
-
bug P2
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆
-
duplicate
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
Quantinuum/tket#2255 ·
維護者通常 1 天內回覆