Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't drop type from type data (TypeData) #476

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/Language/Haskell/Stylish/Step/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,10 @@ putType' cfg lty = case GHC.unLoc lty of
_ -> putType lty

newOrData :: DataDecl -> String
newOrData decl = if isNewtype decl then "newtype" else "data"
newOrData decl
| isNewtype decl = "newtype"
| isTypeData decl = "type data"
| otherwise = "data"

isGADT :: DataDecl -> Bool
isGADT = any isGADTCons . GHC.dd_cons . dataDefn
Expand All @@ -533,6 +536,9 @@ isGADT = any isGADTCons . GHC.dd_cons . dataDefn
isNewtype :: DataDecl -> Bool
isNewtype = (== GHC.NewType) . GHC.dataDefnConsNewOrData . GHC.dd_cons . dataDefn

isTypeData :: DataDecl -> Bool
isTypeData = GHC.isTypeDataDefnCons . GHC.dd_cons . dataDefn

isInfix :: DataDecl -> Bool
isInfix = (== GHC.Infix) . dataFixity

Expand Down
9 changes: 9 additions & 0 deletions tests/Language/Haskell/Stylish/Step/Data/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ tests = testGroup "Language.Haskell.Stylish.Step.Data.Tests"
, testCase "case 64" case64
, testCase "case 65" case65
, testCase "case 66 (issue #411)" case66
, testCase "case 67" case67
]

case00 :: Assertion
Expand Down Expand Up @@ -1381,6 +1382,14 @@ case66 = assertSnippet (step indentIndentStyle) input input
, " deriving (Eq, Show)"
]

-- | Don't drop type from type data (TypeData)
case67 :: Assertion
case67 = assertSnippet (step indentIndentStyle) input input
where
input =
[ "type data Foo = A | B | C"
]

sameSameStyle :: Config
sameSameStyle = Config SameLine SameLine 2 2 False True SameLine False True NoMaxColumns

Expand Down