Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Record coercion can construct a private record from outside its module

クローズ
#9,124 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #9125 @cknitt による — マージ済み

評価

難易度
4/5
見積もり時間
1〜2日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
ocaml
領域
compilers

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
OCaml
スター
7.5k
フォーク
484
平均マージ
21時間 9分
マージ済み PR(30日)
255

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rescript-lang/rescript のほかの issue

rescript-lang/rescript の issue をすべて見る

似ている issue

Compilers の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。