Skip to content

Commit 122bcd4

Browse files
amesgenmrkkrp
authored andcommitted
Fix AST diffing for empty Haddock comments in data decls
1 parent c59910b commit 122bcd4

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
* Format parenthesized operators starting with a `#` correctly in the presence
1010
of `UnboxedSums`. [Issue 1062](https://github.com/tweag/ormolu/issues/1062).
1111

12+
* Fix false positives in AST diffing related to empty Haddock comments in data
13+
declarations. [Issue 1065](https://github.com/tweag/ormolu/issues/1065).
14+
1215
## Ormolu 0.7.1.0
1316

1417
* Include `base` fixity information when formatting a Haskell file that's

data/examples/other/empty-haddock-out.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ where
55

66
test ::
77
test
8+
9+
data T = T

data/examples/other/empty-haddock.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ where
99
test ::
1010
-- |
1111
test
12+
13+
data T = T {- ^ -}

src/Ormolu/Parser.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ parseModuleSnippet Config {..} modFixityMap dynFlags path rawInput = liftIO $ do
177177
normalizeModule :: HsModule GhcPs -> HsModule GhcPs
178178
normalizeModule hsmod =
179179
everywhere
180-
(extT (mkT dropBlankTypeHaddocks) patchContext)
180+
(mkT dropBlankTypeHaddocks `extT` dropBlankDataDeclHaddocks `extT` patchContext)
181181
hsmod
182182
{ hsmodImports =
183183
normalizeImports (hsmodImports hsmod),
@@ -204,6 +204,13 @@ normalizeModule hsmod =
204204
L _ (HsDocTy _ ty s) :: LHsType GhcPs
205205
| isBlankDocString s -> ty
206206
a -> a
207+
dropBlankDataDeclHaddocks = \case
208+
ConDeclGADT {con_doc = Just s, ..} :: ConDecl GhcPs
209+
| isBlankDocString s -> ConDeclGADT {con_doc = Nothing, ..}
210+
ConDeclH98 {con_doc = Just s, ..} :: ConDecl GhcPs
211+
| isBlankDocString s -> ConDeclH98 {con_doc = Nothing, ..}
212+
a -> a
213+
207214
patchContext :: LHsContext GhcPs -> LHsContext GhcPs
208215
patchContext = fmap $ \case
209216
[x@(L _ (HsParTy _ _))] -> [x]

0 commit comments

Comments
 (0)