Skip to content

Commit ca77ba9

Browse files
authored
Fix missing parentheses around let..in with attribute (#2564)
On a side note, parentheses around let..in shouldn't have `~fits_break:false`, but changing that would cause large diffs.
1 parent 6aaac03 commit ca77ba9

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ profile. This started with version 0.26.0.
5252
- Fix comments around underscore in record patterns (#2540, @Julow)
5353
- Fix dropped comments before `begin .. end` in a match case (#2541, @Julow)
5454
- Fix closing `*)` in doc-comments exceeding the margin (#2550, @Julow)
55-
- Fix invalid syntax geneated for begin..end attributes (#2551, @Julow)
55+
- Fix invalid syntax generated for begin..end attributes (#2551, @Julow)
5656
The attribute is moved from `begin .. end [@attr]` to `begin [@attr] .. end`.
57+
- Fix missing parentheses around `let .. in [@attr]` (#2564, @Julow)
5758
- Display `a##b` instead of `a ## b` and similarly for operators that start with # (#2580, @v-gb)
5859

5960
### Changes

lib/Fmt_ast.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4476,7 +4476,6 @@ and fmt_structure_item c ~last:last_item ~semisemi {ctx= parent_ctx; ast= si}
44764476

44774477
and fmt_let c ~rec_flag ~bindings ~parens ~fmt_atrs ~fmt_expr ~loc_in
44784478
~body_loc ~has_attr ~indent_after_in =
4479-
let parens = parens || has_attr in
44804479
let fmt_in indent =
44814480
match c.conf.fmt_opts.break_before_in.v with
44824481
| `Fit_or_vertical -> break 1 (-indent) $ str "in"
@@ -4495,13 +4494,14 @@ and fmt_let c ~rec_flag ~bindings ~parens ~fmt_atrs ~fmt_expr ~loc_in
44954494
| `Compact -> space_break )
44964495
in
44974496
let blank_line_after_in = sequence_blank_line c loc_in body_loc in
4498-
Params.Exp.wrap c.conf ~parens:(parens || has_attr) ~fits_breaks:false
4499-
(vbox 0
4500-
( hvbox 0 (list_fl bindings fmt_binding)
4501-
$ ( if blank_line_after_in then str "\n" $ cut_break
4502-
else break 1000 indent_after_in )
4503-
$ hvbox 0 fmt_expr ) )
4504-
$ fmt_atrs
4497+
Params.Exp.wrap c.conf ~parens ~fits_breaks:false
4498+
( Params.Exp.wrap c.conf ~parens:has_attr ~fits_breaks:false
4499+
(vbox 0
4500+
( hvbox 0 (list_fl bindings fmt_binding)
4501+
$ ( if blank_line_after_in then str "\n" $ cut_break
4502+
else break 1000 indent_after_in )
4503+
$ hvbox 0 fmt_expr ) )
4504+
$ fmt_atrs )
45054505

45064506
and fmt_value_constraint c vc_opt =
45074507
let fmt_sep x =

test/passing/tests/lazy.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ let () =
1010
let _ = lazy (a.b <- 1)
1111

1212
let _ = match x with (lazy (Some _ as x)), x -> x
13+
14+
let _ =
15+
lazy
16+
((let () = () in
17+
() )
18+
[@attr] )

0 commit comments

Comments
 (0)