Skip to content

Commit

Permalink
Support DatatypeContexts
Browse files Browse the repository at this point in the history
  • Loading branch information
amesgen authored and mrkkrp committed Apr 24, 2023
1 parent 2ee0dab commit 683e2a2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
1002](https://github.com/tweag/ormolu/issues/1002) and [issue
730](https://github.com/tweag/ormolu/issues/730).

* Support the (deprecated) `DatatypeContexts` extension to avoid surprises.
[Issue 1012](https://github.com/tweag/ormolu/issues/1012).

## Ormolu 0.6.0.1

* Fix false positives in AST diffing related to `UnicodeSyntax`. [PR
Expand Down
11 changes: 11 additions & 0 deletions data/examples/declaration/data/datatype-contexts-out.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
data (IsString s) => T s = T

data
(IsString s) =>
T s = T

data
( IsString s,
IsString s
) =>
T s = T
8 changes: 8 additions & 0 deletions data/examples/declaration/data/datatype-contexts.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
data IsString s => T s = T

data IsString s =>
T s = T

data
( IsString s
, IsString s ) => T s = T
30 changes: 0 additions & 30 deletions expected-failures/brittany.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,6 @@ data/Test394.hs

Formatting is not idempotent.
Please, consider reporting the bug.
data/Test51.hs
@@ -1,14 +1,11 @@
{-# LANGUAGE DatatypeContexts #-}
- data
- ( LooooooooooooooooooooongConstraint a
- , LooooooooooooooooooooongConstraint b
- ) =>
- MyRecord a b
- = MyConstructor
- { foo1, foo2
- :: loooooooooooooooooooooooooooooooong
- -> loooooooooooooooooooooooooooooooong
- , bar :: a
- , bazz :: b
- }

+ data MyRecord a b = MyConstructor
+ { foo1,
+ foo2 ::
+ loooooooooooooooooooooooooooooooong ->
+ loooooooooooooooooooooooooooooooong,
+ bar :: a,
+ bazz :: b
+ }
+

AST of input and AST of formatted code differ.
at data/Test51.hs:(2,1)-(13,5)
Please, consider reporting the bug.
To format anyway, use --unsafe.
data/Test65.hs
@@ -1,9 +1,9 @@
data Foo = Bar
Expand Down
10 changes: 9 additions & 1 deletion src/Ormolu/Printer/Meat/Declaration/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,18 @@ p_dataDecl style name tpats fixity HsDataDefn {..} = do
txt " #-}"
let constructorSpans = getLocA name : fmap lhsTypeArgSrcSpan tpats
sigSpans = maybeToList . fmap getLocA $ dd_kindSig
declHeaderSpans = constructorSpans ++ sigSpans
declHeaderSpans =
maybeToList (getLocA <$> dd_ctxt) ++ constructorSpans ++ sigSpans
switchLayout declHeaderSpans $ do
breakpoint
inci $ do
case dd_ctxt of
Nothing -> pure ()
Just ctxt -> do
located ctxt p_hsContext
space
txt "=>"
breakpoint
switchLayout constructorSpans $
p_infixDefHelper
(isInfix fixity)
Expand Down

0 comments on commit 683e2a2

Please sign in to comment.