Skip to content

Commit d4f12e8

Browse files
committed
Correctly format non-promoted type-level tuples
This can only occur with `NoListTuplePuns`. Closes tweag#1146
1 parent 561af66 commit d4f12e8

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
* 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)
2020
* 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)
2121

22+
* Correctly format non-promoted type-level tuples with `NoListTuplePuns`. [Issue
23+
1146](https://github.com/tweag/ormolu/issues/1146).
24+
2225
## Ormolu 0.7.7.0
2326

2427
* Use single-line layout for parens around single-line content. [Issue
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# LANGUAGE NoListTuplePuns #-}
2+
3+
type X = (Int, String)
4+
5+
type Y = [String, Int]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# Language NoListTuplePuns #-}
2+
3+
type X = (Int, String)
4+
5+
type Y = [String, Int]

src/Ormolu/Printer/Meat/Type.hs

+8-4
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,15 @@ p_hsType' multilineArgs = \case
156156
(IsPromoted, L _ t : _) | startsWithSingleQuote t -> space
157157
_ -> return ()
158158
sep commaDel (sitcc . located' p_hsType) xs
159-
HsExplicitTupleTy _ _p xs -> do
160-
txt "'"
159+
HsExplicitTupleTy _ p xs -> do
160+
case p of
161+
IsPromoted -> txt "'"
162+
NotPromoted -> return ()
161163
parens N $ do
162-
case xs of
163-
L _ t : _ | startsWithSingleQuote t -> space
164+
-- If this tuple is promoted and the first element starts with a single
165+
-- quote, we need to put a space in between or it fails to parse.
166+
case (p, xs) of
167+
(IsPromoted, L _ t : _) | startsWithSingleQuote t -> space
164168
_ -> return ()
165169
sep commaDel (located' p_hsType) xs
166170
HsTyLit _ t ->

0 commit comments

Comments
 (0)