diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cde99c66..c960daa02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ * Use single-line layout for parens around single-line content. [Issue 1120](https://github.com/tweag/ormolu/issues/1120). +* Allow function arguments to be on the same line even if the full type + (with constraints and foralls) are on multiple lines. [PR + 1125](https://github.com/tweag/ormolu/pull/1125) + ## Ormolu 0.7.6.0 * Fix Haddock comments on infix constructors diff --git a/data/examples/declaration/class/default-signatures-out.hs b/data/examples/declaration/class/default-signatures-out.hs index 4d1530d17..ff8a97980 100644 --- a/data/examples/declaration/class/default-signatures-out.hs +++ b/data/examples/declaration/class/default-signatures-out.hs @@ -14,9 +14,7 @@ class Bar a where ( Read a, Semigroup a ) => - a -> - a -> - a + a -> a -> a -- Even more pointless comment bar a diff --git a/data/examples/declaration/data/gadt/multiline-out.hs b/data/examples/declaration/data/gadt/multiline-out.hs index e939ea7d7..ac7dc1778 100644 --- a/data/examples/declaration/data/gadt/multiline-out.hs +++ b/data/examples/declaration/data/gadt/multiline-out.hs @@ -9,9 +9,7 @@ data Foo a where forall a b. (Show a, Eq b) => -- foo -- bar - a -> - b -> - Foo 'Int + a -> b -> Foo 'Int -- | But 'Bar' is also not too bad. Bar :: Int -> Maybe Text -> Foo 'Bool diff --git a/data/examples/declaration/rewrite-rule/type-signature-out.hs b/data/examples/declaration/rewrite-rule/type-signature-out.hs index 3887cecca..44baa5442 100644 --- a/data/examples/declaration/rewrite-rule/type-signature-out.hs +++ b/data/examples/declaration/rewrite-rule/type-signature-out.hs @@ -8,9 +8,7 @@ z ( g :: forall b. - (a -> b -> b) -> - b -> - b + (a -> b -> b) -> b -> b ). foldr k z (build g) = g k z diff --git a/data/examples/declaration/value/function/fancy-forall-0-out.hs b/data/examples/declaration/value/function/fancy-forall-0-out.hs index fd484d0a0..6cf9416c2 100644 --- a/data/examples/declaration/value/function/fancy-forall-0-out.hs +++ b/data/examples/declaration/value/function/fancy-forall-0-out.hs @@ -6,5 +6,4 @@ wrapError :: HasCatch innertag inner (t m'), HasCatch outertag outer m ) => - (forall m'. (HasCatch innertag inner m') => m' a) -> - m a + (forall m'. (HasCatch innertag inner m') => m' a) -> m a diff --git a/data/examples/declaration/value/function/fancy-forall-1-out.hs b/data/examples/declaration/value/function/fancy-forall-1-out.hs index a42a1a7ef..6fa6cf68b 100644 --- a/data/examples/declaration/value/function/fancy-forall-1-out.hs +++ b/data/examples/declaration/value/function/fancy-forall-1-out.hs @@ -6,5 +6,4 @@ magnify :: HasReader innertag inner (t m'), HasReader outertag outer m ) => - (forall m'. (HasReader innertag inner m') => m' a) -> - m a + (forall m'. (HasReader innertag inner m') => m' a) -> m a diff --git a/data/examples/declaration/value/function/implicit-params-out.hs b/data/examples/declaration/value/function/implicit-params-out.hs index acb797600..e88cd005e 100644 --- a/data/examples/declaration/value/function/implicit-params-out.hs +++ b/data/examples/declaration/value/function/implicit-params-out.hs @@ -11,6 +11,5 @@ sort' :: a -> a -> Bool, ?foo :: Int ) => - [a] -> - [a] + [a] -> [a] sort' = sort diff --git a/data/examples/declaration/value/function/multiline-types-out.hs b/data/examples/declaration/value/function/multiline-types-out.hs new file mode 100644 index 000000000..1ab3be5f1 --- /dev/null +++ b/data/examples/declaration/value/function/multiline-types-out.hs @@ -0,0 +1,17 @@ +foo :: + (Monad m, Show a) => + a -> + m String +bar :: + ( Monad m, + Show a + ) => + a -> m String +multiConstraints :: + (Show a) => + a -> + a -> + a -> + (Eq a) => + (Num a) => + a -> a -> () diff --git a/data/examples/declaration/value/function/multiline-types.hs b/data/examples/declaration/value/function/multiline-types.hs new file mode 100644 index 000000000..31a85b359 --- /dev/null +++ b/data/examples/declaration/value/function/multiline-types.hs @@ -0,0 +1,15 @@ +foo :: + (Monad m, Show a) => + a -> + m String + +bar :: + (Monad m, + Show a) => + a -> m String + +multiConstraints :: + Show a => + a -> a -> a -> + Eq a => Num a => + a -> a -> () diff --git a/data/examples/other/multiline-forall-out.hs b/data/examples/other/multiline-forall-out.hs index 55f4a252c..fd9b8a6b4 100644 --- a/data/examples/other/multiline-forall-out.hs +++ b/data/examples/other/multiline-forall-out.hs @@ -22,8 +22,7 @@ data G where ) (x :: *) (y :: *). - f x y -> - G + f x y -> G f :: forall @@ -32,8 +31,7 @@ f :: ) (x :: *) (y :: *). - f x y -> - () + f x y -> () f = const () type family T f x y where diff --git a/src/Ormolu/Printer/Meat/Type.hs b/src/Ormolu/Printer/Meat/Type.hs index 792f4ca96..cc61be66a 100644 --- a/src/Ormolu/Printer/Meat/Type.hs +++ b/src/Ormolu/Printer/Meat/Type.hs @@ -44,7 +44,7 @@ p_hsType' multilineArgs = \case HsForAllInvis _ bndrs -> p_forallBndrs ForAllInvis p_hsTyVarBndr bndrs HsForAllVis _ bndrs -> p_forallBndrs ForAllVis p_hsTyVarBndr bndrs interArgBreak - p_hsTypeR (unLoc t) + located t p_hsType HsQualTy _ qs t -> do located qs p_hsContext space @@ -52,7 +52,7 @@ p_hsType' multilineArgs = \case interArgBreak case unLoc t of HsQualTy {} -> p_hsTypeR (unLoc t) - HsFunTy {} -> p_hsTypeR (unLoc t) + HsFunTy {} -> located t p_hsType _ -> located t p_hsTypeR HsTyVar _ p n -> do case p of