diff --git a/formatTest/typeCheckedTests/expected_output/lazy.re b/formatTest/typeCheckedTests/expected_output/lazy.re index 66c044bb0..6161ee0c6 100644 --- a/formatTest/typeCheckedTests/expected_output/lazy.re +++ b/formatTest/typeCheckedTests/expected_output/lazy.re @@ -1,9 +1,9 @@ let myComputation = - lazy { + lazy({ let tmp = 10; let tmp2 = 20; tmp + tmp2; - }; + }); type myRecord = {myRecordField: int}; @@ -14,18 +14,25 @@ let operateOnLazyValue = (lazy {myRecordField}) => { let result = operateOnLazyValue( - lazy {myRecordField: 100}, + lazy({myRecordField: 100}), ); type box('a) = | Box('a); -let lazy thisIsActuallyAPatternMatch = lazy 200; +let lazy thisIsActuallyAPatternMatch = lazy(200); let tmp: int = thisIsActuallyAPatternMatch; let (lazy (Box(i)), x) = ( - lazy (Box(200)), + lazy(Box(200)), 100, ); let tmp: int = i; -let myComputation = lazy 200; +let myComputation = lazy(200); + +let reallyLoooooooooooooongIdentifierThatSpansMoreThan50Cols = 200; + +let foo = + lazy( + reallyLoooooooooooooongIdentifierThatSpansMoreThan50Cols + ); diff --git a/formatTest/typeCheckedTests/input/lazy.re b/formatTest/typeCheckedTests/input/lazy.re index c259ce8df..19c357dd2 100644 --- a/formatTest/typeCheckedTests/input/lazy.re +++ b/formatTest/typeCheckedTests/input/lazy.re @@ -21,3 +21,7 @@ let (lazy (Box(i)), x) = (lazy (Box(200)), 100); let tmp: int = i; let myComputation = lazy (200); + +let reallyLoooooooooooooongIdentifierThatSpansMoreThan50Cols = 200; + +let foo = lazy(reallyLoooooooooooooongIdentifierThatSpansMoreThan50Cols) diff --git a/formatTest/unit_tests/expected_output/modules_no_semi.re b/formatTest/unit_tests/expected_output/modules_no_semi.re index 28c7e2b73..fd1faa5a5 100644 --- a/formatTest/unit_tests/expected_output/modules_no_semi.re +++ b/formatTest/unit_tests/expected_output/modules_no_semi.re @@ -645,7 +645,7 @@ let test = b => { assert(true); - lazy true; + lazy(true); Fun.ignore(); }; diff --git a/src/reason-parser/reason_pprint_ast.ml b/src/reason-parser/reason_pprint_ast.ml index 58596fcc6..4cd1179de 100644 --- a/src/reason-parser/reason_pprint_ast.ml +++ b/src/reason-parser/reason_pprint_ast.ml @@ -1794,20 +1794,20 @@ let partitionFinalWrapping listTester wrapFinalItemSetting x = let semiTerminated term = makeList [term; atom ";"] (* postSpace is so that when comments are interleaved, we still use spacing rules. *) -let makeLetSequence letItems = +let makeLetSequence ?(wrap=("{", "}")) letItems = makeList ~break:Always_rec ~inline:(true, false) - ~wrap:("{", "}") + ~wrap ~postSpace:true ~sep:(SepFinal (";", ";")) letItems -let makeLetSequenceSingleLine letItems = +let makeLetSequenceSingleLine ?(wrap=("{", "}")) letItems = makeList ~break:IfNeed ~inline:(true, false) - ~wrap:("{", "}") + ~wrap ~preSpace:true ~postSpace:true ~sep:(Sep ";") @@ -5796,7 +5796,16 @@ let printer = object(self:'self) (makeTup [(self#unparseExpr e)]); ) | Pexp_lazy e -> - Some (label ~space:true (atom "lazy") (self#simplifyUnparseExpr e)) + let lazy_atom = atom "lazy" in + let layout_right = match e with + | {pexp_desc = Pexp_let _} -> + makeLetSequence ~wrap:("({", "})") (self#letList e) + | e when isSingleArgParenApplication [e] -> + self#singleArgParenApplication [e] + | _ -> + formatPrecedence (self#unparseExpr e) + in + Some (label lazy_atom layout_right) | Pexp_poly _ -> failwith ( "This version of the pretty printer assumes it is impossible to " ^