Attribute attachment not preserved in refmt.
Open
Nobody has claimed this yet.
KIND: FEATURE REQUEST
Printer
- Dominant language
- OCaml
- Stars
- 10.3k
- Forks
- 438
- PR merge metrics
- No merged PRs in 30d
Description
Repro: 4.02.3 on master branch:
echo '[@attr] x + [@attr2] y;' | refmt
[@attr]
x + [@attr2] y;
echo '([@attr] x) + [@attr2] y;' | refmt
[@attr] x + [@attr2] y;
Notice that the parens were dropped. And they are in fact distinct ASTs, and that distinction is not preserved at print time:
echo '[@attr] x + [@attr2] y;' | refmt --print ast
[
structure_item ([1,0+0]..[1,0+22])
Pstr_eval
attribute "attr"
[]
expression ([1,0+8]..[1,0+22])
Pexp_apply
expression ([1,0+10]..[1,0+11])
Pexp_ident "+" ([1,0+10]..[1,0+11])
[
<label> ""
expression ([1,0+8]..[1,0+9])
Pexp_ident "x" ([1,0+8]..[1,0+9])
<label> ""
expression ([1,0+12]..[1,0+22])
attribute "attr2"
[]
Pexp_ident "y" ([1,0+21]..[1,0+22])
]
]
jwalkes-MacBook:reason jwalke$ echo '([@attr] x) + [@attr2] y;' | refmt --print ast
[
structure_item ([1,0+0]..[1,0+24])
Pstr_eval
expression ([1,0+0]..[1,0+24])
Pexp_apply
expression ([1,0+12]..[1,0+13])
Pexp_ident "+" ([1,0+12]..[1,0+13])
[
<label> ""
expression ([1,0+0]..[1,0+11])
attribute "attr"
[]
Pexp_ident "x" ([1,0+9]..[1,0+10])
<label> ""
expression ([1,0+14]..[1,0+24])
attribute "attr2"
[]
Pexp_ident "y" ([1,0+23]..[1,0+24])
]
]
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two examples with refmt and compare their formatted output with the --print ast output shown in the issue. Trace the refmt formatting path for attributed expressions and parentheses; done means formatting preserves the distinction between the two ASTs without dropping required parentheses.
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
- 35/100