tweag / ormolu

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

Commenting last set of ADT constructors breaks ormolu #489

Closed srid closed 4 years ago

srid commented 4 years ago

For this code:

data Foo
  = Bar
  -- | Baz
  deriving (Show)

Ormolu will fail:

Parsing of source code failed:
  /dev/stdin:34:3-10
  parse error on input `deriving'
utdemir commented 4 years ago

-- | string denotes a Haddock comment, but used in a wrong place in this case.

Quoting @mrkkrp from another issue:

It should be obivous that Ormolu has to work with Haddocks. Both Ormolu and the Haddock executable use GHC parser with a special setting to extract Haddocks. The thing is, though, that once this setting is activated, the input must form a finished Haskell module with correct Haddocks, otherwise it is a parse error.

It's a bit unfortunate that Ormolu fails in a correct Haskell program, but there is nothing much it can do since it is also responsible for reformatting Haddock comments too. A temporary solution in this case would be putting one more space before | so that it is not recognized as a Haddock comment.

mrkkrp commented 4 years ago

Yeah, as @utdemir point out, this is just not a valid input for GHC in Haddock mode and there is little we can do.