tweag / ormolu

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

Breaks leading operator in arrow do block #742

Closed robx closed 3 years ago

robx commented 3 years ago

Describe the bug

ormolu moves a leading operator in arrow do notation to the end of the previous line, breaking some code.

To Reproduce

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

bar f = proc (a, b) ->
  do
    x <- f a -< b
    >-> (\y -> f b >- a)
$ ormolu test.hs
test.hs:6:5
  Parsing of formatted code failed:  parse error (possibly incorrect indentation or mismatched brackets)
$ ormolu --unsafe test.hs
{-# LANGUAGE Arrows #-}

bar f = proc (a, b) ->
  do
    x <- f a -< b >->
    (\y -> a -< f b)

Expected behavior

The code should be formatted to parseable code (with the same AST).

Environment

current master on macos

Additional context

amesgen commented 3 years ago

EDIT This is incorrect.

With #728 (but still with --unsafe),

{-# LANGUAGE Arrows #-}

bar f = proc (a, b) ->
  do
    x <- f a -< b
    >-> (\y -> f b >- a)

is formatted into

{-# LANGUAGE Arrows #-}

bar f = proc (a, b) ->
  do
    x <- f a -< b
  >->
    (\y -> a -< f b)

which is better, but still not correct, as the first argument of >-> in the original snippet is proc (a, b) -> do x <- f a -< b and not just do x <- f a -< b.

I will look into this.

amesgen commented 3 years ago

With #728 (but still with --unsafe),

{-# LANGUAGE Arrows #-}

bar f = proc (a, b) ->
  do
    x <- f a -< b
    >-> (\y -> f b >- a)

is formatted into

{-# LANGUAGE Arrows #-}

bar f = proc (a, b) ->
  do
    x <- f a -< b
  >->
    (\y -> a -< f b)

which has differing AST, but only due to f b >- a vs. a -< f b. So this is another instance of #737, closing as a duplicate.