tweag/ormolu

Constraints in data and newtype declarations are dropped.

fisx opened this issue · 3 comments

fisx commented

Describe the bug
OrmoluCounterexample.hs:

import Prelude
data IsString s => T s = T

then:

$ ormolu OrmoluCounterexample.hs
OrmoluCounterexample.hs
@@ -1,3 +1,4 @@
  import Prelude
- data IsString s => T s = T

+ data T s = T
+

  AST of input and AST of formatted code differ.
    at OrmoluCounterexample.hs:2:1-26
  Please, consider reporting the bug.
  To format anyway, use --unsafe.

$ ormolu --version
ormolu 0.6.0.1
using ghc-lib-parser 9.6.1.20230312

This is semi-intentional as DatatypeContexts are deprecated:

This is widely considered a misfeature, and is going to be removed from the language.

It came up most recently in #885 (comment) and in #725. It would be very easy to support though if that would help in your usecase.

fisx commented

I wasn't aware it's deprecated. Is there an easy way to add that information to the error message? That would be ideal, otherwise maybe it's worth changing it so people won't trip over this again in the future.

I will just figure out how to not use DatatypeContext any more now, so you've already helped me, thanks!

Hmm, warning about DatatypeContexts being deprecated sounds more of a job for GHC than for a formatter (it is already no longer enabled by default when using GHC2021); so I guess the easiest way to improve the current suboptimal experience when formatting DatatypeContexts is to actually support them as that is sufficiently simple, see #1014.