on master help sign in
Always put parens around kind signatures
commitd61b9101ca7e1bd9edbc7767eae69e9c7732a0a8 authormrkkrp <mark.karpov@tweag.io> dateSun 21 Jul 2019, 22:37 (7 years ago) parent116a5a8
3 files changed+25−6
data/examples/declaration/type/misc-kind-signatures-out.hs+6 data/examples/declaration/type/misc-kind-signatures.hs+5 src/Ormolu/Printer/Meat/Type.hs+14−6
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
7070 p_rdrName op
7171 space
7272 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
7379 HsParTy NoExt t ->
7480 parens (located t p_hsType)
7581 HsIParamTy NoExt n t -> sitcc $ do
@@ -79,12 +85,14 @@ p_hsType = \case
7985 txt ":: "
8086 located t p_hsType
8187 HsStarTy NoExt _ -> txt "*"
82− HsKindSig NoExt t k -> sitcc $ do
83− located t p_hsType
84− space -- FIXME
85− inci $ do
86− txt ":: "
87− located k p_hsType
88+ HsKindSig NoExt t k ->
89+ -- NOTE Also see the comment for 'HsParTy'.
90+ parens . sitcc $ do
91+ located t p_hsType
92+ space -- FIXME
93+ inci $ do
94+ txt ":: "
95+ located k p_hsType
8896 HsSpliceTy _ _ -> error "HsSpliceTy"
8997 HsDocTy NoExt _ _ -> error "HsDocTy"
9098 HsBangTy NoExt (HsSrcBang _ u s) t -> do