tweag / ormolu

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

Breaks with multiline arrow bananas in do block #739

Closed robx closed 3 years ago

robx commented 3 years ago

Describe the bug

(EDIT: I first thought this was due to the where clause, instead it's because of the bananas in a do. Updated accordingly.)

ormolu formats a valid expression of the form

foo = do
  (|
      -- body
   |)

to the following which doesn't parse (outdenting the closing bracket)

foo = do
  (|
      -- body
  |)

To Reproduce

$ cat test.hs
{-# LANGUAGE Arrows #-}

foo = proc (x, y) -> do
  (|
    g
      (a -< z)
   |)
$ ormolu test.hs
test.hs:7:3
  Parsing of formatted code failed:  parse error (possibly incorrect indentation or mismatched brackets)
$ ormolu -u test.hs
{-# LANGUAGE Arrows #-}

foo = proc (x, y) -> do
  (|
    g
      (a -< z)
  |)

Expected behavior The code should be formatted to parseable code (with the same AST). That would probably mean keeping the half-indentation level?

Environment current master on macos

robx commented 3 years ago

This isn't related to the problems solved by the half-indent in PR #731, is it?

mrkkrp commented 3 years ago

I think it's not related.