Formatter drops comments in dict patterns, variant spread patterns and dict literal spreads
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
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
Ppat_typeandPpat_variant_spreadattach no comments:
https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/syntax/src/res_comments_table.ml#L2056- Dict pattern rows are walked as record rows, so key comments are attached to the key location:
https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/syntax/src/res_comments_table.ml#L2057-L2063 print_pattern_dict_rowprints the key withprint_longident, which does not consult the comment table. The record row printer usesprint_lident_path ... cmt_tbl.
https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/syntax/src/res_printer.ml#L3051-L3076- The
Ppat_dictcase has noprint_comments_inside:
https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/syntax/src/res_printer.ml#L2845-L2864 - In a dict literal with spreads, each run of rows becomes a synthetic expression. Leading comments attach to that expression (https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/syntax/src/res_comments_table.ml#L1402-L1410), but
print_spread_dict_exprprints the run without printing them (https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/syntax/src/res_printer.ml#L1782-L1786). This cause is from reading the code.
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
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.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rescript-lang/rescript
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
rescript-lang/rescript#8833 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
rewatch watch on Linux stops watching a source folder when an overlapping recursive source folder is removed from rescript.jsonCó thể đã có người làm @cknitt đã nhận 1 ngày trước. Đang mở
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 35/100
rescript-lang/rescript#8825 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
rescript-lang/rescript#8806 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
rescript-lang/rescript#8798 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 58/100
rescript-lang/rescript#8757 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rescript-lang/rescript
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
modelcontextprotocol/inspector#2723 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
ranxianglei/billion-context#3175 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
beginner bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
hiero-ledger/hiero-sdk-js#4517 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug misleading tooling trivial
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
vitest-dev/vitest#11577 ·
Maintainer thường phản hồi trong vòng 1 ngày