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

Compiler crash (matching.ml assertion) on dict and optional-field record patterns mixing a value and `?None` on one key

Đã đóng
#8,810 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

Một pull request liên quan đã được merge.

  • #8842 của @cknitt — đã merge

Đánh giá

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

Hướng nghiên cứu

Start with compiler/ml/matching.ml at get_args_constr around line 1236, then read compiler/ml/dict_pattern.ml around lines 73–102 to understand how dict keys become optional record labels. Reproduce the crash with the supplied dict and optional record pattern examples, and inspect the existing compiler tests for matching. Done means both examples compile without an assertion failure; pull request #8842 is already open.

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

Mô tả

Found by adversarial experiments on semantic analysts.

What is broken

This match makes bsc crash:

let f = (d: dict<int>) =>
  switch d {
  | dict{"x": 1} => 0
  | dict{"y": 2} => 0
  | dict{"x": ?None} => 1
  | _ => 2
  }
$ bsc -nopervasives C1.res
Fatal error: exception File "compiler/ml/matching.ml", line 1236, characters 9-15: Assertion failed

Expected: it compiles. The compiler at ece8b148 produces:

function f(d) {
  if (d.x !== 1 && d.y !== 2) {
    if (d.x !== undefined) { return 2; } else { return 1; }
  } else { return 0; }
}

The assertion is in get_args_constr: https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/ml/matching.ml#L1233-L1236

The same crash happens with a record type that has optional fields, both at master and at ece8b148:

type r = {x?: int, y?: int}
let f = (d: r) =>
  switch d {
  | {x: 1} => 0
  | {y: 2} => 0
  | {x: ?None} => 1   // `?Some(3)` crashes too
  | _ => 2
  }

Any two of the three cases compile. The crash needs a value pattern and an optional pattern (?None or ?Some(_)) on the same key, with a case on another key between them.

Introduced

The record crash is older. Dict patterns reach it since #8751 (e6c46f23b), which lowers every key of a match to one optional record label: https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/ml/dict_pattern.ml#L73-L102

Impact

The compiler crashes, with no source location, on an ordinary dict pattern match that compiled before #8751.

Ngôn ngữ chính
OCaml
Star
7.5k
Fork
484
Merge trung bình
20 giờ 27 phút
Pull request đã merge (30 ngày)
120

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.