Skip to content

Commit 702fac3

Browse files
Fix issue with disappearing GADT kind signatures (#381)
1 parent 1c71623 commit 702fac3

File tree

2 files changed

+21
-1
lines changed
  • lib/Language/Haskell/Stylish/Step
  • tests/Language/Haskell/Stylish/Step/Data

2 files changed

+21
-1
lines changed

lib/Language/Haskell/Stylish/Step/Data.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import GHC.Hs.Types (ConDeclField (..),
3838
HsConDetails (..), HsContext,
3939
HsImplicitBndrs (..),
4040
HsTyVarBndr (..),
41-
HsType (..), LHsQTyVars (..))
41+
HsType (..), LHsQTyVars (..), LHsKind)
4242
import RdrName (RdrName)
4343
import SrcLoc (GenLocated (..), Located,
4444
RealLocated)
@@ -312,9 +312,11 @@ putName decl@MkDataDecl{..} =
312312
putRdrName dataDeclName
313313
space
314314
forM_ secondTvar putOutputable
315+
maybePutKindSig
315316
else do
316317
putRdrName dataDeclName
317318
forM_ (hsq_explicit dataTypeVars) (\t -> space >> putOutputable t)
319+
maybePutKindSig
318320

319321
where
320322
firstTvar :: Maybe (Located (HsTyVarBndr GhcPs))
@@ -330,6 +332,12 @@ putName decl@MkDataDecl{..} =
330332
& drop 1
331333
& listToMaybe
332334

335+
maybePutKindSig :: Printer ()
336+
maybePutKindSig = forM_ maybeKindSig (\k -> space >> putText "::" >> space >> putOutputable k)
337+
338+
maybeKindSig :: Maybe (LHsKind GhcPs)
339+
maybeKindSig = dd_kindSig dataDefn
340+
333341
putConstructor :: Config -> Int -> Located (ConDecl GhcPs) -> P ()
334342
putConstructor cfg consIndent (L _ cons) = case cons of
335343
ConDeclGADT{..} -> do

tests/Language/Haskell/Stylish/Step/Data/Tests.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ tests = testGroup "Language.Haskell.Stylish.Step.Data.Tests"
7575
, testCase "case 60" case60
7676
, testCase "case 61 (issue 282)" case61
7777
, testCase "case 62 (issue 273)" case62
78+
, testCase "case 63 (issue 338)" case63
7879
]
7980

8081
case00 :: Assertion
@@ -1377,6 +1378,17 @@ case62 = expected @=? testStep (step sameIndentStyle) input
13771378
, " }"
13781379
]
13791380

1381+
case63 :: Assertion
1382+
case63 = expected @=? testStep (step indentIndentStyle) input
1383+
where
1384+
input = unlines
1385+
[ "module Herp where"
1386+
, ""
1387+
, "data Foo :: * -> * where"
1388+
, " Bar :: () -> Foo ()"
1389+
]
1390+
expected = input
1391+
13801392
sameSameStyle :: Config
13811393
sameSameStyle = Config SameLine SameLine 2 2 False True SameLine False True NoMaxColumns
13821394

0 commit comments

Comments
 (0)