From ca77ba9844c255f8427cff069fcfa1777dc153e7 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Fri, 11 Oct 2024 10:29:36 +0200 Subject: [PATCH] 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. --- CHANGES.md | 3 ++- lib/Fmt_ast.ml | 16 ++++++++-------- test/passing/tests/lazy.ml | 6 ++++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cc47dff279..14cd6816b4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index 07c5f291df..f69959228f 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -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" @@ -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 = diff --git a/test/passing/tests/lazy.ml b/test/passing/tests/lazy.ml index f9a542b3fa..6b650df88f 100644 --- a/test/passing/tests/lazy.ml +++ b/test/passing/tests/lazy.ml @@ -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] )