Untagged variant switch with a default arm matches instances and literals in the wrong case
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ó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/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
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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).
- Ngôn ngữ chính
- OCaml
- Star
- 7.5k
- Fork
- 483
- Merge trung bình
- 21 giờ 8 phút
- Pull request đã merge (30 ngày)
- 183
Chuẩn bị môi trường
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.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rescript-lang/rescript
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
rescript-lang/rescript#8996 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 70/100
rescript-lang/rescript#8997 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
rescript-lang/rescript#8994 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Issues from differential semantic drift analysis (a7721303 to b123b7c3)Có thể đã có người làm @cknitt đã nhận hôm nay. Đang mở
rescript-lang/rescript#8980 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Doc-comment attributes: editor analysis accepts `@ocaml.doc`/`@ns.doc`, genType and the printer do notCó thể đã có người làm @cknitt đã nhận hôm nay. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
rescript-lang/rescript#8978 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rescript-lang/rescript
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
objectionary/phino#2075 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
bug P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
duplicate
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
numba/numba#10939 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày