summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZubin Duggal <zubin.duggal@gmail.com>2022-01-14 17:18:21 +0530
committerZubin Duggal <zubin.duggal@gmail.com>2022-02-24 02:07:12 +0530
commitf0a0b50fea9a0189dc0095390757d428471b64c9 (patch)
treef66ee3348a1d34ace8872ae875b1ba112d2218f6
parent9ed3bc6e1c09c558bba20e045e61582ba8fbadc7 (diff)
downloadhaskell-wip/th-pp.tar.gz
TH: fix pretty printing of GADTs with multiple constuctors (#20842)wip/th-pp
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Ppr.hs2
-rw-r--r--testsuite/tests/th/T19363.stdout3
-rw-r--r--testsuite/tests/th/T20842.hs9
-rw-r--r--testsuite/tests/th/T20842.stdout3
-rw-r--r--testsuite/tests/th/all.T1
5 files changed, 16 insertions, 2 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
index d9ae558c15..9627f5c256 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Ppr.hs
@@ -452,7 +452,7 @@ ppr_data maybeInst ctxt t argsDoc ksig cs decs
Just n -> pprName' Applied n <+> argsDoc
Nothing -> argsDoc
<+> ksigDoc <+> maybeWhere,
- nest nestDepth (sep (pref $ map ppr cs)),
+ nest nestDepth (vcat (pref $ map ppr cs)),
if null decs
then empty
else nest nestDepth
diff --git a/testsuite/tests/th/T19363.stdout b/testsuite/tests/th/T19363.stdout
index b6d2c30790..fe404302a8 100644
--- a/testsuite/tests/th/T19363.stdout
+++ b/testsuite/tests/th/T19363.stdout
@@ -1,5 +1,6 @@
data Operator_0
- = (:*_1) GHC.Types.Int | (:**_2) {(^**_3) :: GHC.Types.Int}
+ = (:*_1) GHC.Types.Int
+ | (:**_2) {(^**_3) :: GHC.Types.Int}
data (%*%_4) = (:%*%_5)
{-# COMPLETE (:%*%_5) :: (%*%_4) #-}
{-# ANN type (%*%_4) "yargh" #-}
diff --git a/testsuite/tests/th/T20842.hs b/testsuite/tests/th/T20842.hs
new file mode 100644
index 0000000000..6758ea732a
--- /dev/null
+++ b/testsuite/tests/th/T20842.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE TemplateHaskell, GADTs #-}
+module Main where
+
+import Language.Haskell.TH
+
+main :: IO ()
+main = do
+ x <- [d| data MyData where { D1 :: MyData; D2 :: Bool -> MyData } |]
+ putStrLn $ pprint x
diff --git a/testsuite/tests/th/T20842.stdout b/testsuite/tests/th/T20842.stdout
new file mode 100644
index 0000000000..8113be91e4
--- /dev/null
+++ b/testsuite/tests/th/T20842.stdout
@@ -0,0 +1,3 @@
+data MyData_0 where
+ D1_1 :: MyData_0
+ D2_2 :: GHC.Types.Bool -> MyData_0
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index aa953098ce..79cd9ca7d1 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -544,3 +544,4 @@ test('T20590', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
test('T20773', only_ways(['ghci']), ghci_script, ['T20773.script'])
test('T20884', normal, compile_fail, [''])
test('T21038', normal, compile, [''])
+test('T20842', normal, compile_and_run, [''])