[commit: ghc] master: Pretty-printer missing parens for infix class declaration (0e96812)

git at git.haskell.org git at git.haskell.org
Mon Oct 2 18:15:37 UTC 2017


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

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

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

commit 0e9681268a38cbc15c9c2b50979624732c9077ce
Author: Alan Zimmerman <alan.zimm at gmail.com>
Date:   Mon Oct 2 18:09:37 2017 +0200

    Pretty-printer missing parens for infix class declaration
    
        class (a `C` b) c
    
    Is pretty printed as
    
        class a `C` b c
    
    Fixes #14306


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

0e9681268a38cbc15c9c2b50979624732c9077ce
 compiler/hsSyn/HsDecls.hs         |  4 ++++
 testsuite/tests/printer/Makefile  |  4 ++++
 testsuite/tests/printer/T14306.hs | 10 ++++++++++
 testsuite/tests/printer/all.T     |  1 +
 4 files changed, 19 insertions(+)

diff --git a/compiler/hsSyn/HsDecls.hs b/compiler/hsSyn/HsDecls.hs
index ecb11a0..35fccd3 100644
--- a/compiler/hsSyn/HsDecls.hs
+++ b/compiler/hsSyn/HsDecls.hs
@@ -695,6 +695,10 @@ pp_vanilla_decl_head thing (HsQTvs { hsq_explicit = tyvars }) fixity context
  = hsep [pprHsContext context, pp_tyvars tyvars]
   where
     pp_tyvars (varl:varsr)
+      | fixity == Infix && length varsr > 1
+         = hsep [char '(',ppr (unLoc varl), pprInfixOcc (unLoc thing)
+                , (ppr.unLoc) (head varsr), char ')'
+                , hsep (map (ppr.unLoc) (tail varsr))]
       | fixity == Infix
          = hsep [ppr (unLoc varl), pprInfixOcc (unLoc thing)
          , hsep (map (ppr.unLoc) varsr)]
diff --git a/testsuite/tests/printer/Makefile b/testsuite/tests/printer/Makefile
index 1c2f299..4565e83 100644
--- a/testsuite/tests/printer/Makefile
+++ b/testsuite/tests/printer/Makefile
@@ -213,3 +213,7 @@ T13550:
 .PHONY: T13942
 T13942:
 	$(CHECK_PPR) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" T13942.hs
+
+.PHONY: T14306
+T14306:
+	$(CHECK_PPR) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" T14306.hs
diff --git a/testsuite/tests/printer/T14306.hs b/testsuite/tests/printer/T14306.hs
new file mode 100644
index 0000000..c39807e
--- /dev/null
+++ b/testsuite/tests/printer/T14306.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE MultiParamTypeClasses #-}
+module T14306 where
+
+class (a `C` b) c
+
+class (a `D` b) c d
+
+class (a `E` b)
+
+class a `F` b
diff --git a/testsuite/tests/printer/all.T b/testsuite/tests/printer/all.T
index a71d6e3..9a1170e 100644
--- a/testsuite/tests/printer/all.T
+++ b/testsuite/tests/printer/all.T
@@ -50,3 +50,4 @@ test('T13199', ignore_stderr, run_command, ['$MAKE -s --no-print-directory T1319
 test('T13050p', ignore_stderr, run_command, ['$MAKE -s --no-print-directory T13050p'])
 test('T13550', ignore_stderr, run_command, ['$MAKE -s --no-print-directory T13550'])
 test('T13942', ignore_stderr, run_command, ['$MAKE -s --no-print-directory T13942'])
+test('T14306', ignore_stderr, run_command, ['$MAKE -s --no-print-directory T14306'])



More information about the ghc-commits mailing list