Skip to content

AST differs on inline lambda case #1044

@chris-martin

Description

@chris-martin

It look like ormolu is making an incorrect assumption about when it's okay to remove braces.

$ ormolu -i (git ls-files '*.hs')
typeclasses-make-timeline/src/Timeline/Read.hs
@@ -181,6 +186,6 @@
  fixFragment :: Fragment -> Fragment
  fixFragment = coerce $ insertApostrophe . insertEllipsis . insertEmDash
    where
-     insertApostrophe = Text.map \case{ '\'' -> '’'; x -> x }
-     insertEmDash = Text.concat . map \case{ x | x == "--" -> "—"; x -> x } . Text.groupBy ((==) `on` Char.isSpace)
-     insertEllipsis = Text.concat . map \case{ x | x == "..." -> "…"; x -> x } . Text.groupBy ((==) `on` (== '.'))
+     insertApostrophe = Text.map \case '\'' -> '’'; x -> x
+     insertEmDash = Text.concat . map \case x | x == "--" -> "—"; x -> x . Text.groupBy ((==) `on` Char.isSpace)
+     insertEllipsis = Text.concat . map \case x | x == "..." -> "…"; x -> x . Text.groupBy ((==) `on` (== '.'))

  AST of input and AST of formatted code differ.
    at typeclasses-make-timeline/src/Timeline/Read.hs:185:20-74
    at typeclasses-make-timeline/src/Timeline/Read.hs:185:78-89
    at typeclasses-make-timeline/src/Timeline/Read.hs:185:91-114
    at typeclasses-make-timeline/src/Timeline/Read.hs:186:22-77
    at typeclasses-make-timeline/src/Timeline/Read.hs:186:81-92
    at typeclasses-make-timeline/src/Timeline/Read.hs:186:94-113
  Please, consider reporting the bug.
  To format anyway, use --unsafe.
$ ormolu --version
ormolu 0.5.0.1 UNKNOWN UNKNOWN
using ghc-lib-parser 9.2.7.20230228

To work around, I can wrap the lambda case expressions in parentheses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions