From 8787814bd92ad7d97fdf89a396ad292d2c97ab7a Mon Sep 17 00:00:00 2001 From: Dmitry Astapov Date: Wed, 11 Apr 2018 13:25:50 +0100 Subject: [PATCH 1/3] Fix: parens around lists in local opens --- src/Fmt_ast.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Fmt_ast.ml b/src/Fmt_ast.ml index 13b34c84f1..51e492c388 100644 --- a/src/Fmt_ast.ml +++ b/src/Fmt_ast.ml @@ -1375,7 +1375,10 @@ and fmt_expression c ?(box= true) ?epi ?eol ?parens ?ext match e0.pexp_desc with | Pexp_array _ | Pexp_constraint _ | Pexp_record _ | Pexp_tuple _ -> (".", "") - | _ -> (".(", ")") + | _ -> + match sugar_list_exp e0 with + | Some _ -> (".", "") + | None -> (".(", ")") in hvbox 0 ( fits_breaks_if parens "" "(" From 6535cd8d9aa2a9d9ccf5705baf79cfe8a46fdb8a Mon Sep 17 00:00:00 2001 From: Dmitry Astapov Date: Thu, 12 Apr 2018 13:27:12 +0100 Subject: [PATCH 2/3] Fix: do not put parens around patterns enclosed in list --- src/Ast.ml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Ast.ml b/src/Ast.ml index 9b876c9ca4..ed4affeb0b 100644 --- a/src/Ast.ml +++ b/src/Ast.ml @@ -761,6 +761,12 @@ end = struct , Ppat_construct ({txt= Lident "::"}, _) ) when tl == pat -> false + | ( Pat + { ppat_desc= + Ppat_construct + ({txt= Lident "::"}, Some {ppat_desc= Ppat_tuple [_; _]}) } + , (Ppat_construct _| Ppat_variant _) ) -> + false | ( Pat { ppat_desc= Ppat_construct From b4675964db2212dbfa7073c2fe3cbd077e5314c9 Mon Sep 17 00:00:00 2001 From: Dmitry Astapov Date: Thu, 12 Apr 2018 16:43:22 +0100 Subject: [PATCH 3/3] Fix: parens in record update where defaul val is trivial --- src/Ast.ml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Ast.ml b/src/Ast.ml index ed4affeb0b..d70354709c 100644 --- a/src/Ast.ml +++ b/src/Ast.ml @@ -937,6 +937,9 @@ end = struct | Pexp_record (flds, _) when List.exists flds ~f:(fun (_, e0) -> e0 == exp) -> exposed Non_apply exp (* Non_apply is perhaps pessimistic *) + | Pexp_record (_, Some ({pexp_desc= Pexp_apply ({pexp_desc= Pexp_ident {txt= Lident i}},_) } as e0)) + when e0 == exp && is_prefix_id i -> + false | Pexp_record (_, Some ({pexp_desc= Pexp_apply _} as e0)) when e0 == exp -> true