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

Untagged variant with Blob and File cases never matches File when Blob is declared first

Đang mở
#8,938 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

Chưa có ai nhận issue này.

Đá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
48/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
Lĩnh vực
compilers

Hướng nghiên cứu

Start with compiler/ml/ast_untagged_variants.ml, especially type_to_instanceof_backed_obj, and trace how untagged variant cases become ordered instanceof checks. Check the compiler tests for untagged variants and add coverage for File and Blob in both declaration orders. Done means the subclass case is matched first regardless of order, or the unsupported variant is rejected.

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

Mô tả

An untagged variant with cases for a class and one of its subclasses tests them in declaration order, so the subclass case can never match when it is declared second:

@unboxed
type upload = Blob(Blob.t) | File(File.t)

let describe = u =>
  switch u {
  | Blob(_) => "blob"
  | File(_) => "file"
  }

compiles to

function describe(u) {
  if (u instanceof Blob) {
    return "blob";
  } else {
    return "file";
  }
}

File extends Blob, so for File(new File(["x"], "a.txt")) the check u instanceof Blob is true and describe returns "blob" (checked in Node). Declaring File(File.t) | Blob(Blob.t) instead emits u instanceof File and works, whatever the order of the switch cases.

Expected: a subclass is tested before its superclass regardless of declaration order, or the variant is rejected.

Cause: type_to_instanceof_backed_obj in compiler/ml/ast_untagged_variants.ml maps a fixed list of stdlib type names to classes but records no relation between them, so the tests are emitted in declaration order. File/Blob is the only subclass pair in that list today. The same question comes up for user-declared classes (e.g. HTMLElement extends Element) if bindings can declare their runtime class.

Reproduced on current master.

Ngôn ngữ chính
ReScript
Star
7.5k
Fork
483
Merge trung bình
1 ngày 2 giờ
Pull request đã merge (30 ngày)
164

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.