Skip to content

Commit 4cbefb8

Browse files
authored
Don't remove existential quantification (#339) (#344)
Don't remove existential quantification (#339). Also don't remove context from data declarations
1 parent 3333be9 commit 4cbefb8

File tree

3 files changed

+32
-9
lines changed
  • .github/workflows
  • lib/Language/Haskell/Stylish/Step
  • tests/Language/Haskell/Stylish/Step/Data

3 files changed

+32
-9
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
name: Cache ~/.stack
3030
with:
3131
path: ~/.stack
32-
key: ${{ runner.os }}-${{ matrix.ghc }}-v7
32+
key: ${{ runner.os }}-${{ matrix.ghc }}-v8
3333

3434
- name: Add ~/.local/bin to PATH
3535
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -357,19 +357,15 @@ putConstructor cfg consIndent (L _ cons) = case cons of
357357
putText "::"
358358
space
359359

360-
when (unLocated con_forall) do
361-
putText "forall"
362-
space
363-
sep space (fmap putOutputable $ hsq_explicit con_qvars)
364-
dot
365-
space
366-
360+
putForAll con_forall $ hsq_explicit con_qvars
367361
forM_ con_mb_cxt (putContext cfg . unLocated)
368362
putType con_res_ty
369363

370364
XConDecl x ->
371365
noExtCon x
372-
ConDeclH98{..} ->
366+
ConDeclH98{..} -> do
367+
putForAll con_forall con_ex_tvs
368+
forM_ con_mb_cxt (putContext cfg . unLocated)
373369
case con_args of
374370
InfixCon arg1 arg2 -> do
375371
putType arg1
@@ -467,6 +463,15 @@ putNewtypeConstructor cfg (L _ cons) = case cons of
467463
, "GADT encountered in newtype"
468464
]
469465

466+
putForAll :: Located Bool -> [Located (HsTyVarBndr GhcPs)] -> P ()
467+
putForAll forall ex_tvs =
468+
when (unLocated forall) do
469+
putText "forall"
470+
space
471+
sep space (fmap putOutputable ex_tvs)
472+
dot
473+
space
474+
470475
putContext :: Config -> HsContext GhcPs -> P ()
471476
putContext Config{..} = suffix (space >> putText "=>" >> space) . \case
472477
[L _ (HsParTy _ tp)] | cCurriedContext ->

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ tests = testGroup "Language.Haskell.Stylish.Step.Data.Tests"
7171
, testCase "case 56" case56
7272
, testCase "case 57" case57
7373
, testCase "case 58" case58
74+
, testCase "case 59" case59
75+
, testCase "case 60" case60
7476
]
7577

7678
case00 :: Assertion
@@ -1291,6 +1293,22 @@ case58 = expected @=? testStep (step sameIndentStyle) input
12911293

12921294
expected = input
12931295

1296+
-- | Don't remove existential quantification
1297+
--
1298+
-- See https://github.com/haskell/stylish-haskell/issues/339
1299+
case59 :: Assertion
1300+
case59 = assertSnippet (step defaultConfig)
1301+
[ "data Foo = forall (a :: *) . Bar a" ]
1302+
[ "data Foo = forall (a :: *). Bar a" ]
1303+
1304+
-- | Don't remove existential quantification
1305+
--
1306+
-- See https://github.com/haskell/stylish-haskell/issues/339
1307+
case60 :: Assertion
1308+
case60 = assertSnippet (step defaultConfig)
1309+
[ "data Foo = forall a . Bar a" ]
1310+
[ "data Foo = forall a. Bar a" ]
1311+
12941312
sameSameStyle :: Config
12951313
sameSameStyle = Config SameLine SameLine 2 2 False True SameLine False True NoMaxColumns
12961314

0 commit comments

Comments
 (0)