Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constraints in data and newtype declarations are dropped. #1012

Closed
fisx opened this issue Apr 21, 2023 · 3 comments · Fixed by #1014
Closed

Constraints in data and newtype declarations are dropped. #1012

fisx opened this issue Apr 21, 2023 · 3 comments · Fixed by #1014

Comments

@fisx
Copy link
Contributor

fisx commented Apr 21, 2023

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
@amesgen
Copy link
Member

amesgen commented Apr 21, 2023

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
Copy link
Contributor Author

fisx commented Apr 22, 2023

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!

@amesgen
Copy link
Member

amesgen commented Apr 24, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants