Pretty-printer missing parens for infix class declaration
authorAlan Zimmerman <alan.zimm@gmail.com>
Mon, 2 Oct 2017 16:09:37 +0000 (18:09 +0200)
committerAlan Zimmerman <alan.zimm@gmail.com>
Mon, 2 Oct 2017 18:15:11 +0000 (20:15 +0200)
    class (a `C` b) c

Is pretty printed as

    class a `C` b c

Fixes #14306

compiler/hsSyn/HsDecls.hs
testsuite/tests/printer/Makefile
testsuite/tests/printer/T14306.hs [new file with mode: 0644]
testsuite/tests/printer/all.T

index ecb11a0..35fccd3 100644 (file)
@@ -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)]
index 1c2f299..4565e83 100644 (file)
@@ -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 (file)
index 0000000..c39807e
--- /dev/null
@@ -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
index a71d6e3..9a1170e 100644 (file)
@@ -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'])