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

Fix not pretty-printing typeclass constraints with records #849

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Fix the bug of not pretty-printing multiple module-level warning messages ([#822])
- Fix the bug of wrongly converting a `newtype` instance to a `data` one ([#839])
- Fix the bug of not pretty-printing multiple functional dependencies in a typeclass ([#843])
- Fix the bug of not pretty-printing data declarations with records and typeclass constraints ([#849])

### Removed

Expand Down Expand Up @@ -373,6 +374,7 @@ This version is accidentally pushlished, and is the same as 5.3.3.
[@uhbif19]: https://github.com/uhbif19
[@toku-sa-n]: https://github.com/toku-sa-n

[#849]: https://github.com/mihaimaruseac/hindent/pull/849
[#843]: https://github.com/mihaimaruseac/hindent/pull/843
[#839]: https://github.com/mihaimaruseac/hindent/pull/839
[#829]: https://github.com/mihaimaruseac/hindent/pull/829
Expand Down
46 changes: 42 additions & 4 deletions TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,8 @@ data Foo = Foo
Single

```haskell
-- https://github.com/mihaimaruseac/hindent/issues/278
data Link c1 c2 a c =
forall b. (c1 a b, c2 b c) =>
Link (Proxy b)
data D =
forall a. D a
```

Multiple
Expand All @@ -840,6 +838,46 @@ data D =
forall a b c. D a b c
```

With an infix constructor

```haskell
data D =
forall a. a :== a
```

#### Fields with contexts

Without a `forall`

```haskell
data Foo =
Eq a => Foo a
```

With a `forall`

```haskell
-- https://github.com/mihaimaruseac/hindent/issues/278
data Link c1 c2 a c =
forall b. (c1 a b, c2 b c) =>
Link (Proxy b)
```

With an infix constructor without a `forall`

```haskell
data Foo =
Eq a => a :== a
```

With an infix constructor with a `forall`

```haskell
data Foo =
forall a. Eq a =>
a :== a
```

#### Derivings

With a single constructor
Expand Down
76 changes: 51 additions & 25 deletions src/HIndent/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -880,39 +880,65 @@
#endif
#if MIN_VERSION_ghc_lib_parser(9,4,1)
prettyConDecl GHC.ConDeclH98 {con_forall = True, ..} =
(do
string "forall "
spaced $ fmap pretty con_ex_tvs
string ". ")
|=> (do
whenJust con_mb_cxt $ \c -> do
pretty $ Context c
string " =>"
newline
pretty con_name
pretty con_args)
(string "forall " >> spaced (fmap pretty con_ex_tvs) >> string ". ")
|=> (case con_args of
(GHC.InfixCon l r) -> do
whenJust con_mb_cxt $ \c -> do
pretty $ Context c
string " =>"
newline
spaced [pretty l, pretty $ fmap InfixOp con_name, pretty r]
_ -> do
whenJust con_mb_cxt $ \c -> do
pretty $ Context c
string " =>"
newline
pretty con_name
pretty con_args)
prettyConDecl GHC.ConDeclH98 {con_forall = False, ..} =
case con_args of
(GHC.InfixCon l r) -> do
whenJust con_mb_cxt $ \c -> do
pretty $ Context c
string " => "
spaced [pretty l, pretty $ fmap InfixOp con_name, pretty r]
_ -> do
whenJust con_mb_cxt $ \c -> do
pretty $ Context c
string " => "
pretty con_name
pretty con_args
#else
prettyConDecl GHC.ConDeclH98 {con_forall = True, ..} =
(do
string "forall "
spaced $ fmap pretty con_ex_tvs
string ". ")
|=> (do
whenJust con_mb_cxt $ \_ -> do
pretty $ Context con_mb_cxt
string " =>"
newline
pretty con_name
pretty con_args)
#endif
(string "forall " >> spaced (fmap pretty con_ex_tvs) >> string ". ")
|=> (case con_args of
(GHC.InfixCon l r) -> do
whenJust con_mb_cxt $ \_ -> do
pretty $ Context con_mb_cxt
string " =>"
newline
spaced [pretty l, pretty $ fmap InfixOp con_name, pretty r]
_ -> do
whenJust con_mb_cxt $ \_ -> do
pretty $ Context con_mb_cxt
string " =>"
newline
pretty con_name
pretty con_args)
prettyConDecl GHC.ConDeclH98 {con_forall = False, ..} =
case con_args of
(GHC.InfixCon l r) ->
(GHC.InfixCon l r) -> do
whenJust con_mb_cxt $ \_ -> do
pretty $ Context con_mb_cxt
string " => "
spaced [pretty l, pretty $ fmap InfixOp con_name, pretty r]
_ -> do
whenJust con_mb_cxt $ \_ -> do
pretty $ Context con_mb_cxt
string " => "
pretty con_name
pretty con_args

#endif
instance Pretty
(GHC.Match
GHC.GhcPs
Expand All @@ -923,7 +949,7 @@
prettyMatchExpr GHC.Match {m_ctxt = GHC.LambdaExpr, ..} = do
string "\\"
unless (null m_pats)
$ case GHC.unLoc $ head m_pats of

Check warning on line 952 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

In the use of ‘head’

Check warning on line 952 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

In the use of ‘head’

Check warning on line 952 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

In the use of ‘head’

Check warning on line 952 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, 9.8.1)

In the use of ‘head’

Check warning on line 952 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

In the use of `head'

Check warning on line 952 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

In the use of `head'

Check warning on line 952 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

In the use of `head'

Check warning on line 952 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, 9.8.1)

In the use of ‘head’

Check warning on line 952 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

In the use of ‘head’

Check warning on line 952 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

In the use of ‘head’

Check warning on line 952 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

In the use of ‘head’

Check warning on line 952 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, 9.8.1)

In the use of ‘head’
GHC.LazyPat {} -> space
GHC.BangPat {} -> space
_ -> return ()
Expand Down Expand Up @@ -962,7 +988,7 @@
prettyMatchProc GHC.Match {m_ctxt = GHC.LambdaExpr, ..} = do
string "\\"
unless (null m_pats)
$ case GHC.unLoc $ head m_pats of

Check warning on line 991 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

In the use of ‘head’

Check warning on line 991 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

In the use of ‘head’

Check warning on line 991 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

In the use of ‘head’

Check warning on line 991 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, 9.8.1)

In the use of ‘head’

Check warning on line 991 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

In the use of `head'

Check warning on line 991 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

In the use of `head'

Check warning on line 991 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

In the use of `head'

Check warning on line 991 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, 9.8.1)

In the use of ‘head’

Check warning on line 991 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

In the use of ‘head’

Check warning on line 991 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

In the use of ‘head’

Check warning on line 991 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

In the use of ‘head’

Check warning on line 991 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, 9.8.1)

In the use of ‘head’
GHC.LazyPat {} -> space
GHC.BangPat {} -> space
_ -> return ()
Expand Down Expand Up @@ -1644,7 +1670,7 @@
pretty' (GHC.DctMulti _ ts) = hvTuple $ fmap pretty ts

instance Pretty GHC.OverlapMode where
pretty' GHC.NoOverlap {} = notUsedInParsedStage

Check warning on line 1673 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

Pattern match(es) are non-exhaustive

Check warning on line 1673 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

Pattern match(es) are non-exhaustive

Check warning on line 1673 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

Pattern match(es) are non-exhaustive

Check warning on line 1673 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

Pattern match(es) are non-exhaustive

Check warning on line 1673 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

Pattern match(es) are non-exhaustive

Check warning on line 1673 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

Pattern match(es) are non-exhaustive

Check warning on line 1673 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

Pattern match(es) are non-exhaustive

Check warning on line 1673 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

Pattern match(es) are non-exhaustive

Check warning on line 1673 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

Pattern match(es) are non-exhaustive
pretty' GHC.Overlappable {} = string "{-# OVERLAPPABLE #-}"
pretty' GHC.Overlapping {} = string "{-# OVERLAPPING #-}"
pretty' GHC.Overlaps {} = string "{-# OVERLAPS #-}"
Expand Down Expand Up @@ -1805,8 +1831,8 @@
[] -> pure ()
[x'] -> string x'
xs -> do
string $ head xs

Check warning on line 1834 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

In the use of ‘head’

Check warning on line 1834 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

In the use of ‘head’

Check warning on line 1834 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

In the use of ‘head’

Check warning on line 1834 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, 9.8.1)

In the use of ‘head’

Check warning on line 1834 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

In the use of `head'

Check warning on line 1834 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

In the use of `head'

Check warning on line 1834 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

In the use of `head'

Check warning on line 1834 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, 9.8.1)

In the use of ‘head’

Check warning on line 1834 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

In the use of ‘head’

Check warning on line 1834 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

In the use of ‘head’

Check warning on line 1834 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

In the use of ‘head’

Check warning on line 1834 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, 9.8.1)

In the use of ‘head’
indentedWithFixedLevel 0 $ newlinePrefixed $ string <$> tail xs

Check warning on line 1835 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

In the use of ‘tail’

Check warning on line 1835 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

In the use of ‘tail’

Check warning on line 1835 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, nightly)

In the use of ‘tail’

Check warning on line 1835 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, 9.8.1)

In the use of ‘tail’

Check warning on line 1835 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

In the use of `tail'

Check warning on line 1835 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

In the use of `tail'

Check warning on line 1835 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, nightly)

In the use of `tail'

Check warning on line 1835 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, 9.8.1)

In the use of ‘tail’

Check warning on line 1835 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

In the use of ‘tail’

Check warning on line 1835 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

In the use of ‘tail’

Check warning on line 1835 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, nightly)

In the use of ‘tail’

Check warning on line 1835 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, 9.8.1)

In the use of ‘tail’
pretty' (GHC.IEModuleContents _ name) =
pretty $ fmap ModuleNameWithPrefix name
pretty' GHC.IEGroup {} = docNode
Expand Down Expand Up @@ -2231,7 +2257,7 @@
pretty' (GHC.HsFloatPrim _ x) = pretty x >> string "#"
pretty' GHC.HsDoublePrim {} = notUsedInParsedStage
pretty' x =
case x of

Check warning on line 2260 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, 8.10.7)

Pattern match(es) are non-exhaustive

Check warning on line 2260 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, 8.10.7)

Pattern match(es) are non-exhaustive

Check warning on line 2260 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, 8.10.7)

Pattern match(es) are non-exhaustive
GHC.HsString {} -> prettyString
GHC.HsStringPrim {} -> prettyString
where
Expand Down Expand Up @@ -2372,7 +2398,7 @@
string p |=> pretty (fmap StmtLRInsideVerticalList x)
newline
string "]"
stmtsAndPrefixes l = ("| ", head l) : fmap (", ", ) (tail l)

Check warning on line 2401 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, 9.8.1)

In the use of ‘head’

Check warning on line 2401 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (ubuntu-latest, 9.8.1)

In the use of ‘tail’

Check warning on line 2401 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, 9.8.1)

In the use of ‘head’

Check warning on line 2401 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (windows-latest, 9.8.1)

In the use of ‘tail’

Check warning on line 2401 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, 9.8.1)

In the use of ‘head’

Check warning on line 2401 in src/HIndent/Pretty.hs

View workflow job for this annotation

GitHub Actions / CI (macos-latest, 9.8.1)

In the use of ‘tail’

instance Pretty DoExpression where
pretty' DoExpression {..} = do
Expand Down
Loading