From f0a0b50fea9a0189dc0095390757d428471b64c9 Mon Sep 17 00:00:00 2001 From: Zubin Duggal Date: Fri, 14 Jan 2022 17:18:21 +0530 Subject: TH: fix pretty printing of GADTs with multiple constuctors (#20842) --- libraries/template-haskell/Language/Haskell/TH/Ppr.hs | 2 +- testsuite/tests/th/T19363.stdout | 3 ++- testsuite/tests/th/T20842.hs | 9 +++++++++ testsuite/tests/th/T20842.stdout | 3 +++ testsuite/tests/th/all.T | 1 + 5 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 testsuite/tests/th/T20842.hs create mode 100644 testsuite/tests/th/T20842.stdout 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, ['']) -- cgit v1.2.1