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 construct a private record from outside its module

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

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

Đá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
52/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 by tracing the record coercion type-checking path in the ReScript compiler and compare it with the handling of mutable from #9063, fixed by #9086. Check both examples in this issue: coercion from a plain record and from another module’s private record should be rejected, while coercion out to a plain record should remain allowed. Done means those cases behave as expected and the compiler’s relevant regression tests pass.

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

Mô tả

A record coerces structurally into a private record with the same fields, so code outside a module can construct values of that module's private record type, although private means they can only be built inside it.

From a plain record:

module Blob: {
  type t = private {size: float}
} = {
  type t = {size: float}
}

type plain = {size: float}
let fake = (p: plain): Blob.t => (p :> Blob.t)   // compiles: `return p`

From another module's private record with the same fields, which that module constructs freely:

module Fake: {
  type t = private {size: float}
  let make: float => t
} = {
  type t = {size: float}
  let make = size => {size: size}
}

let forged = (Fake.make(1.) :> Blob.t)   // compiles: `{size: 1}`

Expected: a coercion into a private record type is refused, unless the source is that same type. Coercing out of a private record, into a plain record with the same fields, stays allowed: reading a private record is fine.

This is a prerequisite for @instanceOf on private records (#9058): there, a forged value would be dispatched as an instance of a class it isn't. It is the same family as #9063 (fixed by #9086), where record coercion ignored mutable.

Found on master 3562ce6b80.

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

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.