From b274e17764743b985b7262e779046b48b2be0748 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Fri, 24 Mar 2023 21:57:26 +0100 Subject: [PATCH 1/2] Add failing test --- tests/passing/js-let.ml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/passing/js-let.ml b/tests/passing/js-let.ml index 7065f9c4..fc9b9d5a 100644 --- a/tests/passing/js-let.ml +++ b/tests/passing/js-let.ml @@ -40,3 +40,20 @@ let parenthesized_let_tweak = S.S.g s.S.s ~s in y) + +let indentation_after_fun = + fun foo -> + bar + +let indentation_after_fun = + let f = + fun foo -> + bar + in + () + +module M = struct + let indentation_after_fun = + fun foo -> + bar +end From ffc678c7d908eeccf50d583cd028dccbff668b7b Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sat, 25 Mar 2023 00:49:28 +0100 Subject: [PATCH 2/2] Consistent indentation of `fun` after `let` Apply the same indentation for: let f = fun x -> y and: let _ = let f = fun x -> y in () The reason for this change is that a top-level-`let` can be interpreted as a `LetIn`, for example: module M = struct let indentation_after_fun = fun foo -> bar end --- src/indentBlock.ml | 5 +++-- tests/passing/js-let.ml | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/indentBlock.ml b/src/indentBlock.ml index 9933965b..c1852094 100644 --- a/src/indentBlock.ml +++ b/src/indentBlock.ml @@ -1177,7 +1177,7 @@ let rec update_path config block stream tok = | KParen | KBegin | KBracket | KBrace | KBracketBar | KWith(KMatch|KTry) | KBar(KMatch|KTry) | KArrow(KMatch|KTry) | KFun - | KBody(KType|KExternal) | KColon + | KBody(KType|KExternal|KLet) | KColon | KStruct | KSig | KObject | KExtendedItem _ | KExtendedExpr _ -> true | _ -> false) @@ -1187,10 +1187,11 @@ let rec update_path config block stream tok = | {kind=KFun} :: ({kind=KExpr i} as e) :: path when i = prio_flatop -> (* eg '>>= fun x ->': indent like the top of the expression *) {e with kind = KExpr 0} :: path - | {kind=KFun; line } :: {kind=KBody KLet; line=letline} :: _ + | {kind=KFun; line } :: {kind=KBody(KLet|KLetIn); line=letline} :: _ when next_offset tok stream = None && line = current_line && line <> letline -> + (* Special indentation of [fun] inside a [let]. *) append (KArrow KFun) L ~pad:0 (reset_line_indent config line path) | {kind=KFun; line; _ } :: _ when next_offset tok stream = None diff --git a/tests/passing/js-let.ml b/tests/passing/js-let.ml index fc9b9d5a..1855ff70 100644 --- a/tests/passing/js-let.ml +++ b/tests/passing/js-let.ml @@ -48,12 +48,13 @@ let indentation_after_fun = let indentation_after_fun = let f = fun foo -> - bar + bar in () +(* Let is wrongly interpreted as LetIn *) module M = struct let indentation_after_fun = fun foo -> - bar + bar end