tweag / ormolu

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

Overloaded labels (hash) syntax gets formatted with space after hash sign #1078

Closed zzantares closed 6 months ago

zzantares commented 8 months ago

Describe the bug

Formatting a file that uses overloaded labels without declaring the OverloadedLabels extension in the file, inserts a space after hash sign after formatting.

To Reproduce

Given this file:

{-# LANGUAGE DataKinds #-}

module Web.Controller.Posts where

import Data.Function ((&))

(|>) = (&)

validateField = undefined

nonEmpty = undefined

title = undefined

buildPost post =
  post
    |> validateField #title nonEmpty

Using ormolu sample.hs to format it results in (note the extra space in # title:

{-# LANGUAGE DataKinds #-}

module Web.Controller.Posts where

import Data.Function ((&))

(|>) = (&)

validateField = undefined

nonEmpty = undefined

title = undefined

buildPost post =
  post
    |> validateField
    # title nonEmpty

Expected behavior To behave as if the OverloadedLabels was explicitly enabled in the file, thus producing this output:

{-# LANGUAGE DataKinds #-}

module Web.Controller.Posts where

import Data.Function ((&))

(|>) = (&)

validateField = undefined

nonEmpty = undefined

title = undefined

buildPost post =
  post
    |> validateField #title nonEmpty

Environment

Additional context This does not occur if the file has {-# LANGUAGE OverloadedLabels #-} at the top, but it does when the extension is enabled via the *.cabal file.

amesgen commented 8 months ago

Can you post a concrete example of the folder structure (.cabal file plus Haskell source file) which reproduces the problem?

mrkkrp commented 6 months ago

Closing due to lack of activity. @zzantares, feel free to re-open. If you want us to look at this please provide a more complete example @amesgen asked for. For this kind of problem it is important how Cabal file is written and what package component your source file belongs to.