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

Record coercion can turn an immutable field into a mutable one

Đã đóng
#9,063 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

@cknitt đang làm issue này rồi.

Từ ngày 27/10/2026.

  • #9086 của @cknitt — đang mở

Đá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
57/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
ocaml
Lĩnh vực
compilers

Hướng nghiên cứu

Start with Record_coercion.check_record_fields in compiler/ml/record_coercion.ml and read how it checks field names, optionality, runtime names, and field type subtyping. Trace the coercion checks for immutable and mutable fields, then add coverage for the shown ro to rw case and for fields mutable on both sides. Done when the first coercion is rejected and the mutable-to-mutable case requires equal field types.

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

Mô tả

What happens

:> between record types accepts a target whose field is mutable when the source's field is not:

type ro = {x: float}
type rw = {mutable x: float}

let toRw = (r: ro) => (r :> rw)

compiles on master (1a49d918e) to

function toRw(r) {
  return r;
}

So a value typed ro, whose x the type system treats as immutable, can be written through the coerced view:

let r: ro = {x: 0.}
let w = (r :> rw)
w.x = 1.   // compiles; r.x is now 1.

Where

Record_coercion.check_record_fields (compiler/ml/record_coercion.ml) compares field names, optionality and runtime names, and passes the field types on for subtyping; it does not compare mutability.

Expected

A coercion should not grant write access the source does not have: a mutable target field requires a mutable source field. Where both are mutable, the field type is read and written, so it has to be equal (invariant) rather than a subtype.

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

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.