Formatter drops comments in dict patterns, variant spread patterns and dict literal spreads
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- OCaml
- Estrellas
- 7.5k
- Forks
- 484
- Merge medio
- 18 h 19 min
- PR fusionados (30 d)
- 116
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rescript-lang/rescript
-
Build-test fixtures that no longer test what they claimPosiblemente ocupada @cknitt la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
rescript-lang/rescript#8827 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
rescript-lang/rescript#8833 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
rewatch watch on Linux stops watching a source folder when an overlapping recursive source folder is removed from rescript.jsonPosiblemente ocupada @cknitt la tomó hace 1 día. Abierto
Dificultad 4/5 1-2 días Aptitud para principiantes 35/100
rescript-lang/rescript#8825 ·
Los mantenedores suelen responder en 1 día
-
JSX preserve mode spreads an `@unboxed` props record (`{..."x"}` instead of `"x"`)Posiblemente ocupada @cknitt la tomó hace 1 día. Abierto
Dificultad 4/5 1-2 días Aptitud para principiantes 25/100
rescript-lang/rescript#8813 ·
Los mantenedores suelen responder en 1 día
-
Compiler crash (matching.ml assertion) on dict and optional-field record patterns mixing a value and `?None` on one keyPosiblemente ocupada @cknitt la tomó hace 1 día. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
rescript-lang/rescript#8810 ·
Los mantenedores suelen responder en 1 día
Todos los issues de rescript-lang/rescript
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 80/100
gems-uff/noworkflow#233 ·
-
lane:repo
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
SPARDiffData/differential-data-collection#42 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
dbfixtures/pytest-elasticsearch#1001 ·
Los mantenedores suelen responder en 1 día
-
test(refresh): pin FeedOperationTracker soft-timeout cancellation and cleanup (mutation survivors)Abiertoarea: refresh priority: low
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
amatya-aditya/obsidian-rss-dashboard#1105 ·
Los mantenedores suelen responder en 1 día