Skip to content

Commit

Permalink
Fix missing parentheses around let..in with attribute (#2564)
Browse files Browse the repository at this point in the history
On a side note, parentheses around let..in shouldn't have
`~fits_break:false`, but changing that would cause large diffs.
  • Loading branch information
Julow authored Oct 11, 2024
1 parent 6aaac03 commit ca77ba9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ profile. This started with version 0.26.0.
- Fix comments around underscore in record patterns (#2540, @Julow)
- Fix dropped comments before `begin .. end` in a match case (#2541, @Julow)
- Fix closing `*)` in doc-comments exceeding the margin (#2550, @Julow)
- Fix invalid syntax geneated for begin..end attributes (#2551, @Julow)
- Fix invalid syntax generated for begin..end attributes (#2551, @Julow)
The attribute is moved from `begin .. end [@attr]` to `begin [@attr] .. end`.
- Fix missing parentheses around `let .. in [@attr]` (#2564, @Julow)
- Display `a##b` instead of `a ## b` and similarly for operators that start with # (#2580, @v-gb)

### Changes
Expand Down
16 changes: 8 additions & 8 deletions lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4476,7 +4476,6 @@ and fmt_structure_item c ~last:last_item ~semisemi {ctx= parent_ctx; ast= si}

and fmt_let c ~rec_flag ~bindings ~parens ~fmt_atrs ~fmt_expr ~loc_in
~body_loc ~has_attr ~indent_after_in =
let parens = parens || has_attr in
let fmt_in indent =
match c.conf.fmt_opts.break_before_in.v with
| `Fit_or_vertical -> break 1 (-indent) $ str "in"
Expand All @@ -4495,13 +4494,14 @@ and fmt_let c ~rec_flag ~bindings ~parens ~fmt_atrs ~fmt_expr ~loc_in
| `Compact -> space_break )
in
let blank_line_after_in = sequence_blank_line c loc_in body_loc in
Params.Exp.wrap c.conf ~parens:(parens || has_attr) ~fits_breaks:false
(vbox 0
( hvbox 0 (list_fl bindings fmt_binding)
$ ( if blank_line_after_in then str "\n" $ cut_break
else break 1000 indent_after_in )
$ hvbox 0 fmt_expr ) )
$ fmt_atrs
Params.Exp.wrap c.conf ~parens ~fits_breaks:false
( Params.Exp.wrap c.conf ~parens:has_attr ~fits_breaks:false
(vbox 0
( hvbox 0 (list_fl bindings fmt_binding)
$ ( if blank_line_after_in then str "\n" $ cut_break
else break 1000 indent_after_in )
$ hvbox 0 fmt_expr ) )
$ fmt_atrs )

and fmt_value_constraint c vc_opt =
let fmt_sep x =
Expand Down
6 changes: 6 additions & 0 deletions test/passing/tests/lazy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ let () =
let _ = lazy (a.b <- 1)

let _ = match x with (lazy (Some _ as x)), x -> x

let _ =
lazy
((let () = () in
() )
[@attr] )

0 comments on commit ca77ba9

Please sign in to comment.