Skip to content

Commit

Permalink
Correctly format non-promoted type-level tuples
Browse files Browse the repository at this point in the history
This can only occur with `NoListTuplePuns`.

Closes #1146
  • Loading branch information
amesgen committed Jan 15, 2025
1 parent 0641dad commit fefa883
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
* GHC proposal [#281](https://github.com/ghc-proposals/ghc-proposals/blob/c9401f037cb22d1661931b2ec621925101052997/proposals/0281-visible-forall.rst): accept more types in terms: `forall` quantifications, constraint arrows `=>`, type arrows `->` (enabled by default)
* Part of GHC proposal [#425](https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0425-decl-invis-binders.rst): wildcard binders (enabled by default)

* Correctly format non-promoted type-level tuples with `NoListTuplePuns`. [Issue
1146](https://github.com/tweag/ormolu/issues/1146).

## Ormolu 0.7.7.0

* Use single-line layout for parens around single-line content. [Issue
Expand Down
5 changes: 5 additions & 0 deletions data/examples/declaration/type/promotion-no-puns-out.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{-# LANGUAGE NoListTuplePuns #-}

type X = (Int, String)

type Y = [String, Int]
5 changes: 5 additions & 0 deletions data/examples/declaration/type/promotion-no-puns.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{-# Language NoListTuplePuns #-}

type X = (Int, String)

type Y = [String, Int]
12 changes: 8 additions & 4 deletions src/Ormolu/Printer/Meat/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,15 @@ p_hsType' multilineArgs = \case
(IsPromoted, L _ t : _) | startsWithSingleQuote t -> space
_ -> return ()
sep commaDel (sitcc . located' p_hsType) xs
HsExplicitTupleTy _ _p xs -> do
txt "'"
HsExplicitTupleTy _ p xs -> do
case p of
IsPromoted -> txt "'"
NotPromoted -> return ()
parens N $ do
case xs of
L _ t : _ | startsWithSingleQuote t -> space
-- If this tuple is promoted and the first element starts with a single
-- quote, we need to put a space in between or it fails to parse.
case (p, xs) of
(IsPromoted, L _ t : _) | startsWithSingleQuote t -> space
_ -> return ()
sep commaDel (located' p_hsType) xs
HsTyLit _ t ->
Expand Down

0 comments on commit fefa883

Please sign in to comment.