tweag / ormolu

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

multilines arrow expression enclosed in parenthesis format syntax error #1144

Closed guibou closed 17 hours ago

guibou commented 3 days ago

Describe the bug

When trying to format a multiline arrow expression enclosed with parenthesis, ormolu generates an incorrect result.

To Reproduce

The following file:

{-# LANGUAGE Arrows #-}
import Control.Arrow

foo :: () -> ()
foo = proc () -> do
  (proc () -> 
    returnA -< ()
    ) -< ()

Calling ormolu -i on it leads to:

Bug.hs:9:3
  Parsing of formatted code failed:
  [GHC-58481] parse error (possibly incorrect indentation or mismatched brackets)

We can force the result to be written on disk, with ormolu -i -u, which leads to:

{-# LANGUAGE Arrows #-}

import Control.Arrow

foo :: () -> ()
foo = proc () -> do
  ( proc () ->
      returnA -< ()
  )
    -<
      ()

See how the parenthesis are aligned, which is incorrect. The file can be fixed by indenting by 1 space the closing space. I'm unsure about the details of the correct arrow syntax here.

Note that the arrow expression must be multiline to trigger this behavior.

Expected behavior

Ormolu should not fail to format on these arrows syntax.

Environment

Additional context Add any other context about the problem here.

amesgen commented 3 days ago

Thanks! Fix is in #1145