Hacktoberfest 2026:维护者为十月标记出来的 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 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

已经有一个关联 PR 被合并了。

  • #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
平均合并
1 天 1 小时
30 天内合并 PR
120

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rescript-lang/rescript 的其他 Issue

查看 rescript-lang/rescript 的全部 Issue

相似的 Issue

更多 Compilers Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。