Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta
#8,820 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@cknitt já está trabalhando nisso.

Desde 12/10/2026.

  • #8850 de @cknitt — aberto

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
ocaml
Domínio
testing, tooling

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

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

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de rescript-lang/rescript

Todas as issues de rescript-lang/rescript

Issues semelhantes

Mais issues de Testing & QA

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.