@@ -15,6 +15,7 @@ import GHC
1515import Ormolu.Imports
1616import Ormolu.Printer.Combinators
1717import Ormolu.Printer.Comments
18+import Ormolu.Printer.Internal (isNewlineModified)
1819import Ormolu.Printer.Meat.Common
1920import Ormolu.Printer.Meat.Declaration
2021import Ormolu.Printer.Meat.Declaration.Warning
@@ -54,7 +55,13 @@ p_hsModule exts (L moduleSpan HsModule {..}) = do
5455 forM_ (sortImports hsmodImports) (located' p_hsmodImport)
5556 when (hasImports && hasDecls) newline
5657 p_hsDecls Free hsmodDecls
57− when hasDecls newline
5858 trailingComments <- hasMoreComments
59+ when hasDecls $ do
60+ newlineModified <- isNewlineModified
61+ newline
62+ -- In this case we need to insert a newline between the comments
63+ -- output as a side effect of the previous newline and trailing
64+ -- comments to prevent them from merging.
65+ when (newlineModified && trailingComments) newline
5966 when (trailingComments && hasModuleHeader) newline
6067 spitRemainingComments