tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
958 stars 83 forks source link

Mixing comment styles causes error #521

Closed istathar closed 4 years ago

istathar commented 4 years ago

This code (highlighted here) uses an idiom that I use quite a bit. We put Haddock in multi-line {-| ... -} comments (partly so they can be margin aligned text, and partly because editors syntax highlight colour such text differently) and code comments in -- wherever needed.

{-|
Parse a Tablet. This consumes trailing space around initial delimiter and
removes blank lines within the table (they're not syntactically meaningful)
but only consumes a single newline after trailing delimeter, leaving
further consumption to pStatement.
-}
-- TODO this doesn't preserve alternate syntax if employed by user
pTablet :: Parser Tablet
pTablet = do
    ...

Doing both together caused ormolu to error out with the following message:

AST of input and AST of formatted code differ.
  at lib/Technique/Parser.hs:(328,1)-(333,2)
Please, consider reporting the bug.

Removing the code comment line allowed the formatter to work, but we noticed that it ate the multi-line comment and turned it into --| ... which is suboptimal from the point of view of differentiating Haddock comments from code comments. Is this something that could be reconsidered?

mrkkrp commented 4 years ago

We prefer inline style of comments. As many other things about formatting it is a matter of taste. Otherwise I'm closing this as a duplicate of #589 (well, your issue is older but it is also a request to change our current haddock style).