Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Formatter drops comments in dict patterns, variant spread patterns and dict literal spreads

已关闭
#8,820 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

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

  • #8850 来自 @cknitt —— 已合并

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
ocaml
领域
testing, tooling

调研方向

Start with res_comments_table.ml and res_printer.ml at the locations linked in the issue, then review the comment fixtures under tests/syntax_tests/data/printer/comments/. Reproduce with the provided cm.res command and add fixture cases for dict patterns and variant spread patterns. Done means formatting preserves every listed comment and the fixtures catch losses on the first print.

由索引模型根据 Issue 内容生成。

描述

Found by adversarial experiments on semantic analysts.

What is broken

The formatter deletes comments in these positions:

  • Dict pattern key: | dict{"a" /* k */: b} → | dict{"a": b}
  • Dict pattern value: | dict{"a": /* c */ a} → | dict{"a": a} (the record pattern {a: /* c */ a} keeps its comment)
  • Empty dict pattern: | dict{/* e */} → | dict{}
  • Variant spread pattern: | .../* c */ t → | ...t
  • Polymorphic variant type pattern: | #.../* c */ t → | #...t
  • Dict literal with a spread: an own-line comment before the first row after a spread is dropped (/* x */ on the same line is kept)

Reproduction

cm.res:

let f = d =>
  switch d {
  | dict{"a" /* k */: b} => b
  | dict{"a": /* c */ a} => a
  | dict{/* e */} => 0
  | _ => 1
  }
type t = A | B
type u = | ...t | C
let g = x =>
  switch x {
  | .../* c */ t => 0
  | #.../* c */ t => 0
  | C => 1
  }
let b = dict{
  ...base,
  // first
  "a": 1,
}
./_build/default/compiler/syntax/cli/res_cli.exe cm.res

Observed: every comment above is missing from the output. Expected: each comment is printed.

Where

No comment fixture covers dict patterns or variant spread patterns (tests/syntax_tests/data/printer/comments/). The roundtrip test compares the first formatting with the second, so a comment lost on the first print passes. The fix should add these cases to the comment fixtures.

Introduced by

The same output is produced at ece8b148, before the dict pattern and variant spread nodes existed. The current code comes from b081cd19c (#8749) and bffd18e7b (#8742).

Impact

Running the formatter silently deletes user comments.

主要语言
OCaml
星标
7.5k
派生
484
平均合并
20 小时 27 分钟
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

更多 Testing & QA Issue

把新 issue 发到你的邮箱

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