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

Compiler crash (matching.ml assertion) on dict and optional-field record patterns mixing a value and `?None` on one key

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

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

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

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

評価

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

調査の方向性

Start with compiler/ml/matching.ml at get_args_constr around line 1236, then read compiler/ml/dict_pattern.ml around lines 73–102 to understand how dict keys become optional record labels. Reproduce the crash with the supplied dict and optional record pattern examples, and inspect the existing compiler tests for matching. Done means both examples compile without an assertion failure; pull request #8842 is already open.

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

説明

Found by adversarial experiments on semantic analysts.

What is broken

This match makes bsc crash:

let f = (d: dict<int>) =>
  switch d {
  | dict{"x": 1} => 0
  | dict{"y": 2} => 0
  | dict{"x": ?None} => 1
  | _ => 2
  }
$ bsc -nopervasives C1.res
Fatal error: exception File "compiler/ml/matching.ml", line 1236, characters 9-15: Assertion failed

Expected: it compiles. The compiler at ece8b148 produces:

function f(d) {
  if (d.x !== 1 && d.y !== 2) {
    if (d.x !== undefined) { return 2; } else { return 1; }
  } else { return 0; }
}

The assertion is in get_args_constr: https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/ml/matching.ml#L1233-L1236

The same crash happens with a record type that has optional fields, both at master and at ece8b148:

type r = {x?: int, y?: int}
let f = (d: r) =>
  switch d {
  | {x: 1} => 0
  | {y: 2} => 0
  | {x: ?None} => 1   // `?Some(3)` crashes too
  | _ => 2
  }

Any two of the three cases compile. The crash needs a value pattern and an optional pattern (?None or ?Some(_)) on the same key, with a case on another key between them.

Introduced

The record crash is older. Dict patterns reach it since #8751 (e6c46f23b), which lowers every key of a match to one optional record label: https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/ml/dict_pattern.ml#L73-L102

Impact

The compiler crashes, with no source location, on an ordinary dict pattern match that compiled before #8751.

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

環境構築

Codespaces で開く

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

はじめの一歩

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

rescript-lang/rescript のほかの issue

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

似ている issue

Compilers の issue をもっと見る

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

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