Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đã đóng
#8,820 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Một pull request liên quan đã được merge.

  • #8850 của @cknitt — đã merge

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
ocaml
Lĩnh vực
testing, tooling

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
OCaml
Star
7.5k
Fork
484
Merge trung bình
20 giờ 27 phút
Pull request đã merge (30 ngày)
120

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rescript-lang/rescript

Tất cả issue của rescript-lang/rescript

Issue tương tự

Thêm issue về Testing & QA

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.