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 7065f9c4..1855ff70 100644 --- a/tests/passing/js-let.ml +++ b/tests/passing/js-let.ml @@ -40,3 +40,21 @@ 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 + () + +(* Let is wrongly interpreted as LetIn *) +module M = struct + let indentation_after_fun = + fun foo -> + bar +end