diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e12260..203a1b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Ormolu 0.1.2.0 + +* Fixed the bug when comments in different styles got glued together after + formatting. [Issue 589](https://github.com/tweag/ormolu/issues/589). + ## Ormolu 0.1.1.0 * Imports in a import lists are now normalized: duplicate imports are diff --git a/data/examples/other/comment-glued-together-out.hs b/data/examples/other/comment-glued-together-out.hs new file mode 100644 index 0000000..c968e8f --- /dev/null +++ b/data/examples/other/comment-glued-together-out.hs @@ -0,0 +1,7 @@ +module Main (main) where + +-- | Foo. + +-- Bar +main :: IO () +main = return () diff --git a/data/examples/other/comment-glued-together.hs b/data/examples/other/comment-glued-together.hs new file mode 100644 index 0000000..bfbf2d6 --- /dev/null +++ b/data/examples/other/comment-glued-together.hs @@ -0,0 +1,6 @@ +module Main (main) where + +{- | Foo. -} +-- Bar +main :: IO () +main = return () diff --git a/expected-failures/idris.txt b/expected-failures/idris.txt index 4b7a7a8..9e4b3b3 100644 --- a/expected-failures/idris.txt +++ b/expected-failures/idris.txt @@ -2,10 +2,6 @@ The GHC parser (in Haddock mode) failed: src/Idris/Parser.hs:1052:1 parse error on input `@' -AST of input and AST of formatted code differ. - at src/Idris/Parser/Data.hs:281:1-29 -Please, consider reporting the bug. - The GHC parser (in Haddock mode) failed: src/Idris/Parser/Expr.hs:75:1 parse error on input `@' diff --git a/src/Ormolu/Printer/Comments.hs b/src/Ormolu/Printer/Comments.hs index b2ba004..37ba94b 100644 --- a/src/Ormolu/Printer/Comments.hs +++ b/src/Ormolu/Printer/Comments.hs @@ -154,6 +154,7 @@ needsNewlineBefore :: -- | Last printed comment span Maybe SpanMark -> Bool +needsNewlineBefore _ (Just (HaddockSpan _ _)) = True needsNewlineBefore l mlastMark = case spanMarkSpan <$> mlastMark of Nothing -> False @@ -238,8 +239,7 @@ commentFollowsElt ref mnSpn meSpn mlastMark (L l comment) = -- lexemes in front of it and goes right after the previous comment. not (hasAtomsBefore comment) && ( case mlastMark of - Just (HaddockSpan _ spn) -> - srcSpanEndLine spn + 1 == srcSpanStartLine l + Just (HaddockSpan _ _) -> False Just (CommentSpan spn) -> srcSpanEndLine spn + 1 == srcSpanStartLine l _ -> False