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

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

オープン
#8,938 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

@cknitt がすでに取り組んでいます。

2026年10月21日 から。

  • #8948 @cknitt による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
javascript
領域
compilers

調査の方向性

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.

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

説明

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.

主要言語
OCaml
スター
7.5k
フォーク
483
平均マージ
1日 1時間
マージ済み PR(30日)
169

環境構築

Codespaces で開く

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

はじめの一歩

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

rescript-lang/rescript のほかの issue

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

似ている issue

Compilers の issue をもっと見る

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

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