Formatter drops comments in dict patterns, variant spread patterns and dict literal spreads
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 35/100
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- OCaml
- Estrelas
- 7.5k
- Forks
- 484
- Merge médio
- 18h 19min
- PRs com merge (30d)
- 116
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de rescript-lang/rescript
-
Build-test fixtures that no longer test what they claimTalvez já em andamento @cknitt assumiu há 1 dia. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
rescript-lang/rescript#8827 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
rescript-lang/rescript#8833 · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
rewatch watch on Linux stops watching a source folder when an overlapping recursive source folder is removed from rescript.jsonTalvez já em andamento @cknitt assumiu há 1 dia. Aberta
Dificuldade 4/5 1-2 dias Facilidade para iniciantes 35/100
rescript-lang/rescript#8825 ·
Mantenedores costumam responder em até 1 dia
-
JSX preserve mode spreads an `@unboxed` props record (`{..."x"}` instead of `"x"`)Talvez já em andamento @cknitt assumiu há 1 dia. Aberta
Dificuldade 4/5 1-2 dias Facilidade para iniciantes 25/100
rescript-lang/rescript#8813 ·
Mantenedores costumam responder em até 1 dia
-
Compiler crash (matching.ml assertion) on dict and optional-field record patterns mixing a value and `?None` on one keyTalvez já em andamento @cknitt assumiu há 1 dia. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
rescript-lang/rescript#8810 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de rescript-lang/rescript
Issues semelhantes
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
luckyframework/lucky#2058 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
nmfs-ost/stockplotr#416 ·
Mantenedores costumam responder em até 1 dia
-
lane:threads todo:ticket
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
Mantenedores costumam responder em até 1 dia
-
bug cellranger-multi
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia