Skip to content

Semicolons removed from multi-line or patterns #1183

@00-kat

Description

@00-kat

Describe the bug

Ormolu gobbles up the semicolons from or patterns that span multiple lines, resulting in this error (code below):

repro.hs
@@ -3,8 +3,10 @@
  data Foo = A | B | C | D deriving (Show)

- food foo@(A;
-           B;
-           C) = Just foo
+ food
+   foo@( A
+         B
+         C
+         ) = Just foo
  food _ = Nothing

  main = mapM (print . food) [A, B, C, D]

  AST of input and AST of formatted code differ.
    at repro.hs:(5,11)-(7,11)
  Please, consider reporting the bug.
  To format anyway, use --unsafe.
Running the code before formatting works just fine.
$ runhaskell repro.hs
Just A
Just B
Just C
Nothing
And as the error message implies, running the formatted (with --unsafe) code doesn't work, because the semicolon isn't redundant in or patterns.
$ ormolu --unsafe -i repro.hs && runhaskell repro.hs
repro.hs:6:9: error: [GHC-27346]
    • The data constructor ‘A’ should have no arguments, but has been given 2
    • In the pattern: A B C
      In an equation for ‘food’: food foo@(A B C) = Just foo
  |
6 |   foo@( A
  |         ^...

To Reproduce

Run Ormolu on:

{-# LANGUAGE OrPatterns #-}

data Foo = A | B | C | D deriving (Show)

food foo@(A;
          B;
          C) = Just foo
food _ = Nothing

main = mapM (print . food) [A, B, C, D]

Expected behavior

The semicolons stay; or more specifically, Ormolu doesn't error.

Environment

  • OS name + version: Arch Linux (rolling release)
  • Version of the code: reproduces on both 0.8.0.2 and 8d609ae (latest commit at time of writing)

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