tweag / ormolu

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

Not idempotent with comment in let-block #687

Closed brandon-leapyear closed 4 months ago

brandon-leapyear commented 3 years ago

Describe the bug The following source code will be reformatted twice:

foo :: IO ()
foo = let
  foo' = do
    putStrLn "hi"
  -- test
  in foo' >> putStrLn "bye"

To Reproduce Run ormolu the first time gets

 foo :: IO ()
-foo =
-  let foo' = do
-       putStrLn "hi"
-       -- test
-  in foo' >> putStrLn "bye"
+foo = let
+  foo' = do
+    putStrLn "hi"
+  -- test
+  in foo' >> putStrLn "bye"

Run ormolu again rewrites it again to:

 foo :: IO ()
 foo =
   let foo' = do
         putStrLn "hi"
-  -- test
-  in foo' >> putStrLn "bye"
+  in -- test
+     foo' >> putStrLn "bye"

Any future runs of ormolu will not make any changes

Expected behavior Should go from the original to the last change directly

Environment

Additional context Add any other context about the problem here.

mrkkrp commented 4 months ago

As of 0.7.6.0 this example seems to be directly formatted in the latter version:

foo :: IO ()
foo =
  let foo' = do
        putStrLn "hi"
   in -- test
      foo' >> putStrLn "bye"