Skip to content

Commit

Permalink
Fix AST diffing for empty Haddock comments in data decls
Browse files Browse the repository at this point in the history
  • Loading branch information
amesgen authored and mrkkrp committed Sep 6, 2023
1 parent c59910b commit 122bcd4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* Format parenthesized operators starting with a `#` correctly in the presence
of `UnboxedSums`. [Issue 1062](https://github.com/tweag/ormolu/issues/1062).

* Fix false positives in AST diffing related to empty Haddock comments in data
declarations. [Issue 1065](https://github.com/tweag/ormolu/issues/1065).

## Ormolu 0.7.1.0

* Include `base` fixity information when formatting a Haskell file that's
Expand Down
2 changes: 2 additions & 0 deletions data/examples/other/empty-haddock-out.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ where

test ::
test

data T = T
2 changes: 2 additions & 0 deletions data/examples/other/empty-haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ where
test ::
-- |
test

data T = T {- ^ -}
9 changes: 8 additions & 1 deletion src/Ormolu/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ parseModuleSnippet Config {..} modFixityMap dynFlags path rawInput = liftIO $ do
normalizeModule :: HsModule GhcPs -> HsModule GhcPs
normalizeModule hsmod =
everywhere
(extT (mkT dropBlankTypeHaddocks) patchContext)
(mkT dropBlankTypeHaddocks `extT` dropBlankDataDeclHaddocks `extT` patchContext)
hsmod
{ hsmodImports =
normalizeImports (hsmodImports hsmod),
Expand All @@ -204,6 +204,13 @@ normalizeModule hsmod =
L _ (HsDocTy _ ty s) :: LHsType GhcPs
| isBlankDocString s -> ty
a -> a
dropBlankDataDeclHaddocks = \case
ConDeclGADT {con_doc = Just s, ..} :: ConDecl GhcPs
| isBlankDocString s -> ConDeclGADT {con_doc = Nothing, ..}
ConDeclH98 {con_doc = Just s, ..} :: ConDecl GhcPs
| isBlankDocString s -> ConDeclH98 {con_doc = Nothing, ..}
a -> a

patchContext :: LHsContext GhcPs -> LHsContext GhcPs
patchContext = fmap $ \case
[x@(L _ (HsParTy _ _))] -> [x]
Expand Down

0 comments on commit 122bcd4

Please sign in to comment.