Follow-up to #13887, for promoted infix constructors
authorRyan Scott <ryan.gl.scott@gmail.com>
Sat, 29 Jul 2017 23:36:42 +0000 (19:36 -0400)
committerRyan Scott <ryan.gl.scott@gmail.com>
Sat, 29 Jul 2017 23:36:42 +0000 (19:36 -0400)
Summary:
Correct a couple more spots in the TH pretty-printer by applying the
appropriate parenthesization for infix names. Fixes #13887 (again).

Test Plan: make test TEST=T13887

Reviewers: austin, bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #13887

Differential Revision: https://phabricator.haskell.org/D3802

libraries/template-haskell/Language/Haskell/TH/Ppr.hs
testsuite/tests/th/T13887.hs [new file with mode: 0644]
testsuite/tests/th/T13887.stdout [new file with mode: 0644]
testsuite/tests/th/TH_PromotedList.stderr
testsuite/tests/th/TH_RichKinds2.stderr
testsuite/tests/th/all.T

index 696c445..e6c3302 100644 (file)
@@ -689,11 +689,11 @@ pprParendType (UnboxedSumT arity) = hashParens $ hcat $ replicate (arity-1) bar
 pprParendType ArrowT              = parens (text "->")
 pprParendType ListT               = text "[]"
 pprParendType (LitT l)            = pprTyLit l
-pprParendType (PromotedT c)       = text "'" <> ppr c
+pprParendType (PromotedT c)       = text "'" <> pprName' Applied c
 pprParendType (PromotedTupleT 0)  = text "'()"
 pprParendType (PromotedTupleT n)  = quoteParens (hcat (replicate (n-1) comma))
 pprParendType PromotedNilT        = text "'[]"
-pprParendType PromotedConsT       = text "(':)"
+pprParendType PromotedConsT       = text "'(:)"
 pprParendType StarT               = char '*'
 pprParendType ConstraintT         = text "Constraint"
 pprParendType (SigT ty k)         = parens (ppr ty <+> text "::" <+> ppr k)
diff --git a/testsuite/tests/th/T13887.hs b/testsuite/tests/th/T13887.hs
new file mode 100644 (file)
index 0000000..8687447
--- /dev/null
@@ -0,0 +1,13 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE TemplateHaskell #-}
+module Main where
+
+import Data.Proxy
+import GHC.Generics
+import Language.Haskell.TH
+
+main :: IO ()
+main = do
+  putStrLn $([t| Proxy  (:*:) |] >>= stringE . pprint)
+  putStrLn $([t| Proxy '(:*:) |] >>= stringE . pprint)
+  putStrLn $([t| Proxy '(:)   |] >>= stringE . pprint)
diff --git a/testsuite/tests/th/T13887.stdout b/testsuite/tests/th/T13887.stdout
new file mode 100644 (file)
index 0000000..48845be
--- /dev/null
@@ -0,0 +1,3 @@
+Data.Proxy.Proxy (GHC.Generics.:*:)
+Data.Proxy.Proxy '(GHC.Generics.:*:)
+Data.Proxy.Proxy '(GHC.Types.:)
index 8a6422f..fde888f 100644 (file)
@@ -1,3 +1,3 @@
 
-TH_PromotedList.hs:11:3: Warning:
-    (':) GHC.Types.Int ((':) GHC.Types.Bool '[])
+TH_PromotedList.hs:11:3: warning:
+    '(:) GHC.Types.Int ('(:) GHC.Types.Bool '[])
index 1182929..6b06622 100644 (file)
@@ -5,5 +5,6 @@ TH_RichKinds2.hs:24:4: warning:
     SJust_4 :: (s_5 a_6) -> SMaybe_0 s_5 ('GHC.Base.Just a_6)
 type instance TH_RichKinds2.Map f_7 '[] = '[]
 type instance TH_RichKinds2.Map f_8
-                                ('GHC.Types.: h_9 t_10) = 'GHC.Types.: (f_8 h_9)
-                                                                       (TH_RichKinds2.Map f_8 t_10)
+                                ('(GHC.Types.:) h_9 t_10) = '(GHC.Types.:) (f_8 h_9)
+                                                                           (TH_RichKinds2.Map f_8
+                                                                                              t_10)
index 3db9857..29a6334 100644 (file)
@@ -391,4 +391,5 @@ test('T13781', normal, compile, ['-v0'])
 test('T13782', normal, compile, [''])
 test('T13837', normal, compile_fail, ['-v0 -dsuppress-uniques'])
 test('T13856', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
+test('T13887', normal, compile_and_run, ['-v0'])
 test('T13968', normal, compile_fail, ['-v0'])