[commit: ghc] master: Fix #14817 by not double-printing data family instance kind signatures (aef2b42)

git at git.haskell.org git at git.haskell.org
Fri Mar 2 21:07:47 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/aef2b429072e3d3bbdbcb9e4082a0d86ba329d9e/ghc

>---------------------------------------------------------------

commit aef2b429072e3d3bbdbcb9e4082a0d86ba329d9e
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date:   Fri Mar 2 14:18:15 2018 -0500

    Fix #14817 by not double-printing data family instance kind signatures
    
    Within `pprDataFamInstDecl`, we were invoking `pprFamInstLHS` to
    pretty-print a data family instance header, and we were passing `Just` a
    kind signature to `pprFamInstLHS` to make it pretty-print the kind
    signature alongside it (this is a consequence of commit
    d1ef223cfebd23c25489a4b0c67fbaa2f91c1ec6). But this is silly, because
    then invoke `pp_data_defn`, which //also// pretty-prints the kind
    signature, resulting in the kind signature being printed twice by
    mistake.
    
    This fix is simple—pass `Nothing` to `pprFamInstLHS` instead.
    
    Test Plan: make test TEST=T14817
    
    Reviewers: alanz, bgamari, mpickering
    
    Reviewed By: mpickering
    
    Subscribers: mpickering, rwbarton, thomie, carter
    
    GHC Trac Issues: #14817
    
    Differential Revision: https://phabricator.haskell.org/D4418


>---------------------------------------------------------------

aef2b429072e3d3bbdbcb9e4082a0d86ba329d9e
 compiler/hsSyn/HsDecls.hs        | 5 ++++-
 testsuite/tests/th/T14817.hs     | 6 ++++++
 testsuite/tests/th/T14817.stderr | 7 +++++++
 testsuite/tests/th/all.T         | 1 +
 4 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/compiler/hsSyn/HsDecls.hs b/compiler/hsSyn/HsDecls.hs
index 8078582..475e31e 100644
--- a/compiler/hsSyn/HsDecls.hs
+++ b/compiler/hsSyn/HsDecls.hs
@@ -1555,7 +1555,10 @@ pprDataFamInstDecl top_lvl (DataFamInstDecl { dfid_eqn = HsIB { hsib_body =
   = pp_data_defn pp_hdr defn
   where
     pp_hdr ctxt = ppr_instance_keyword top_lvl
-              <+> pprFamInstLHS tycon pats fixity ctxt (dd_kindSig defn)
+              <+> pprFamInstLHS tycon pats fixity ctxt Nothing
+                    -- No need to pass an explicit kind signature to
+                    -- pprFamInstLHS here, since pp_data_defn already
+                    -- pretty-prints that. See #14817.
 
 pprDataFamInstFlavour :: DataFamInstDecl pass -> SDoc
 pprDataFamInstFlavour (DataFamInstDecl { dfid_eqn = HsIB { hsib_body =
diff --git a/testsuite/tests/th/T14817.hs b/testsuite/tests/th/T14817.hs
new file mode 100644
index 0000000..1019dec
--- /dev/null
+++ b/testsuite/tests/th/T14817.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE TypeFamilies #-}
+module T14817 where
+
+$([d| data family Foo :: *
+      data instance Foo :: * |])
diff --git a/testsuite/tests/th/T14817.stderr b/testsuite/tests/th/T14817.stderr
new file mode 100644
index 0000000..7c63763
--- /dev/null
+++ b/testsuite/tests/th/T14817.stderr
@@ -0,0 +1,7 @@
+T14817.hs:(5,3)-(6,31): Splicing declarations
+    [d| data family Foo :: *
+        
+        data instance Foo :: * |]
+  ======>
+    data family Foo :: GHC.Types.Type
+    data instance Foo :: GHC.Types.Type
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index 4156716..7305800 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -399,3 +399,4 @@ test('T14204', normal, compile_fail, ['-v0'])
 test('T14060', normal, compile_and_run, ['-v0'])
 test('T14646', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
 test('T14681', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
+test('T14817', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])



More information about the ghc-commits mailing list