tweag / ormolu

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

record-dot-preprocessor updates are lost sometimes #658

Closed neongreen closed 3 years ago

neongreen commented 4 years ago

Input:

{-# OPTIONS_GHC -fplugin=RecordDotPreprocessor #-}

foo = a{b = c
 }

fooplus f n = f{foo = f.bar + n}

Output:

{-# OPTIONS_GHC -fplugin=RecordDotPreprocessor #-}

foo =
  a { b = c
    }

fooplus f n = f{foo = f.bar + n}

The right result should be:

{-# OPTIONS_GHC -fplugin=RecordDotPreprocessor #-}

foo =
  a{b = c
   }

fooplus f n = f{foo = f.bar + n}
neongreen commented 4 years ago

The bug is somewhere in https://github.com/tweag/ormolu/pull/499.

neongreen commented 4 years ago

Hm, it's fishier than I thought. Input:

{-# OPTIONS_GHC -fplugin=RecordDotPreprocessor #-}

foo =   req
          { a = b 
          }

Output:


{-# OPTIONS_GHC -fplugin=RecordDotPreprocessor #-}

foo =
  req{ a = b
     }

But now if you remove one of the spaces before req, you don't get the RDP update anymore. The correct behavior is that there should not an RDP update in either case. Input:

{-# OPTIONS_GHC -fplugin=RecordDotPreprocessor #-}

foo =  req
          { a = b 
          }

Output:

{-# OPTIONS_GHC -fplugin=RecordDotPreprocessor #-}

foo =
  req
    { a = b
    }
neongreen commented 4 years ago

@Avi-D-coder can you take another look at this?

neongreen commented 4 years ago

Oops, mis-copied the last example. I edited the comment.

cattingcat commented 3 years ago

@neongreen Workin on fix here: https://github.com/tweag/ormolu/pull/663