reasonml / reasonml/reason

[refmt] Odd reformatting for side-effectful function and comment

Open
#2,010 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

KIND: BUG Parser
Dominant language
OCaml
Stars
10.3k
Forks
438
PR merge metrics
No merged PRs in 30d

Description

Input

{
  f(i);
  /* some comment here */
}

This is the smallest input I've seen replicate the behavior. I originally found this in a for loop.

Expected Output

The { } seem redundant, so I'd expect refmt to just remove them.

f(i);
/* some comment here */

Actual Output

f(
  i,
  /* some comment here */
);

Instead it seems to try to call f with more than a single parameter, which at first sight looks like it should be an error. From utop

utop # let f x = x;;
val f : 'a -> 'a = <fun>
utop # f(1,);;
Error: Syntax error: operator expected.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the smallest case with refmt using the Reason input shown, then compare its output with the expected standalone statements. Trace the formatter path responsible for comments inside a block or for-loop and verify that the result preserves the comment without turning it into an extra function argument.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.