ormolu icon indicating copy to clipboard operation
ormolu copied to clipboard

Idempotency issue with comment between case and where clause

Open buggymcbugfix opened this issue 2 years ago • 2 comments

$ cat repro.hs
foo =
  case x of
    _ -> 1
    -- comment
    where
      x = 1

$ ormolu -c repro.hs
repro.hs
@@ -1,6 +1,7 @@
  foo =
    case x of
      _ -> 1
-     -- comment
    where
+     -- comment
+
      x = 1

  Formatting is not idempotent.
  Please, consider reporting the bug.

$ ormolu --version
ormolu 0.3.0.0 HEAD 06b767c8b70e60321a4debc4599127446f958e5b
using ghc-lib-parser 9.0.1.20210324

Note that the issue goes away when moving the case up:

$ cat good.hs
foo = case x of
    _ -> 1
    -- comment
    where
      x = 1

$ ormolu -c good.hs
foo = case x of
  _ -> 1
  -- comment
  where
    x = 1

buggymcbugfix avatar Sep 22 '21 18:09 buggymcbugfix

Thanks for your reports! If you found them by applying Ormolu to a particular project, and it is open source, we could add it to the set of packages which are automatically tested on CI.

amesgen avatar Sep 22 '21 20:09 amesgen

I found these bugs by running ormolu on closed source code, but feel free to use my minimal repros in your tests.

buggymcbugfix avatar Sep 22 '21 22:09 buggymcbugfix