danstiner / hfmt

Format Haskell programs. Inspired by the gofmt utility.
MIT License
125 stars 14 forks source link

Fix failing hindent on `using` infix operator #28

Closed sergey-kintsel closed 6 years ago

sergey-kintsel commented 6 years ago

I am trying to format this code:

x = a `using` b

and I get this:

Error reformatting example.hs: <interactive>:1:12: Parse error: using

The thing is that if I change using to usingA it works just fine. I debugged it a bit and got to this line: https://github.com/danstiner/hfmt/blob/master/src/Language/Haskell/Format.hs#L36 I have experimented with the list of formatters and it appears that indeed hindent fails. The funny thing is that hindent itself doesn't break if I run it alone.

The easiest solution is to follow the way hindent itself uses reformat function https://github.com/commercialhaskell/hindent/blob/889e1655c6eb170e0d30c3c1173f7fba87041736/src/main/Test.hs#L32

sergey-kintsel commented 6 years ago

@danstiner could you take a look please?

danstiner commented 6 years ago

Nice catch and thanks for the PR! What you pointed to is test code, but the main entry-point uses the same default extensions: https://github.com/commercialhaskell/hindent/blob/0721221ede01d6a3468e562fd7ea0df114de34e2/src/HIndent.hs#L312

I'll try to cut a new point release soon with this fix.