on master help sign in
Always put parens around kind signatures
d61b910mrkkrp
data/examples/declaration/type/misc-kind-signatures-out.hsnew file+6
@@ -0,0 +1,6 @@
1+instance DemoteNodeTypes ('[] :: [NodeType]) where
2+
3+ demoteNodeTypes _ = []
4+
5+b :: (Bool :: *)
6+b = True
data/examples/declaration/type/misc-kind-signatures.hsnew file+5
@@ -0,0 +1,5 @@
1+instance DemoteNodeTypes ('[] :: [NodeType]) where
2+ demoteNodeTypes _ = []
3+
4+b :: (Bool :: *)
5+b = True
src/Ormolu/Printer/Meat/Type.hs+14−6
@@ -70,6 +70,12 @@ p_hsType = \case
70 p_rdrName op
70 p_rdrName op
71 space
71 space
72 located y p_hsType
72 located y p_hsType
73+ HsParTy NoExt (L _ t@HsKindSig {}) ->
74+ -- NOTE Kind signatures already put parentheses around in all cases, so
75+ -- skip this layer of parentheses. The reason for this behavior is that
76+ -- parentheses are not always encoded with 'HsParTy', but seem to be
77+ -- always necessary when we have kind signatures in place.
78+ p_hsType t
73 HsParTy NoExt t ->
79 HsParTy NoExt t ->
74 parens (located t p_hsType)
80 parens (located t p_hsType)
75 HsIParamTy NoExt n t -> sitcc $ do
81 HsIParamTy NoExt n t -> sitcc $ do
@@ -79,12 +85,14 @@ p_hsType = \case
79 txt ":: "
85 txt ":: "
80 located t p_hsType
86 located t p_hsType
81 HsStarTy NoExt _ -> txt "*"
87 HsStarTy NoExt _ -> txt "*"
82− HsKindSig NoExt t k -> sitcc $ do
88+ HsKindSig NoExt t k ->
89+ -- NOTE Also see the comment for 'HsParTy'.
90+ parens . sitcc $ do
83− located t p_hsType
91+ located t p_hsType
84− space -- FIXME
92+ space -- FIXME
85− inci $ do
93+ inci $ do
86− txt ":: "
94+ txt ":: "
87− located k p_hsType
95+ located k p_hsType
88 HsSpliceTy _ _ -> error "HsSpliceTy"
96 HsSpliceTy _ _ -> error "HsSpliceTy"
89 HsDocTy NoExt _ _ -> error "HsDocTy"
97 HsDocTy NoExt _ _ -> error "HsDocTy"
90 HsBangTy NoExt (HsSrcBang _ u s) t -> do
98 HsBangTy NoExt (HsSrcBang _ u s) t -> do