summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Eisenberg <rae@cs.brynmawr.edu>2018-10-17 10:46:21 -0400
committerRichard Eisenberg <rae@cs.brynmawr.edu>2018-10-17 10:46:21 -0400
commit38c28c1a8bb129141e533866700e7318314f32c1 (patch)
treec7ba72ebd399fe15a6b520f28557dad0b7489f0a
parent2e1df7c1556fc2fb6f7449ae07a382c57a0a536c (diff)
downloadhaskell-38c28c1a8bb129141e533866700e7318314f32c1.tar.gz
Fix #15761 by adding parens
This was just a pretty-printer infelicity. Fixed now. Test case: printer/T15761
-rw-r--r--compiler/hsSyn/HsDecls.hs16
-rw-r--r--testsuite/tests/printer/T15761.hs5
-rw-r--r--testsuite/tests/printer/T15761.stderr5
-rw-r--r--testsuite/tests/printer/all.T1
4 files changed, 20 insertions, 7 deletions
diff --git a/compiler/hsSyn/HsDecls.hs b/compiler/hsSyn/HsDecls.hs
index 2d2e911645..55f3b73686 100644
--- a/compiler/hsSyn/HsDecls.hs
+++ b/compiler/hsSyn/HsDecls.hs
@@ -1764,13 +1764,15 @@ pprFamInstLHS thing typats fixity context mb_kind_sig
-- explicit type patterns
= hsep [ pprHsContext context, pp_pats typats, pp_kind_sig ]
where
- pp_pats (patl:patsr)
- | fixity == Infix
- = hsep [pprHsType (unLoc patl), pprInfixOcc (unLoc thing)
- , hsep (map (pprHsType.unLoc) patsr)]
- | otherwise = hsep [ pprPrefixOcc (unLoc thing)
- , hsep (map (pprHsType.unLoc) (patl:patsr))]
- pp_pats [] = pprPrefixOcc (unLoc thing)
+ pp_pats (patl:patr:pats)
+ | Infix <- fixity
+ = let pp_op_app = hsep [ ppr patl, pprInfixOcc (unLoc thing), ppr patr ] in
+ case pats of
+ [] -> pp_op_app
+ _ -> hsep (parens pp_op_app : map ppr pats)
+
+ pp_pats pats = hsep [ pprPrefixOcc (unLoc thing)
+ , hsep (map ppr pats)]
pp_kind_sig
| Just k <- mb_kind_sig
diff --git a/testsuite/tests/printer/T15761.hs b/testsuite/tests/printer/T15761.hs
new file mode 100644
index 0000000000..866002f0f0
--- /dev/null
+++ b/testsuite/tests/printer/T15761.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE TypeFamilies, TypeOperators #-}
+
+data family (a + b) c d
+
+data instance (Int + Bool) Double = Float
diff --git a/testsuite/tests/printer/T15761.stderr b/testsuite/tests/printer/T15761.stderr
new file mode 100644
index 0000000000..10425b43e6
--- /dev/null
+++ b/testsuite/tests/printer/T15761.stderr
@@ -0,0 +1,5 @@
+
+T15761.hs:5:1: error:
+ • Expecting one more argument to ‘(Int + Bool) Double’
+ Expected a type, but ‘(Int + Bool) Double’ has kind ‘* -> *’
+ • In the data instance declaration for ‘+’
diff --git a/testsuite/tests/printer/all.T b/testsuite/tests/printer/all.T
index 203efa4be4..7f45c74a6a 100644
--- a/testsuite/tests/printer/all.T
+++ b/testsuite/tests/printer/all.T
@@ -56,3 +56,4 @@ test('T14289c', ignore_stderr, run_command, ['$MAKE -s --no-print-directory T142
test('T14306', ignore_stderr, run_command, ['$MAKE -s --no-print-directory T14306'])
test('T14343', normal, compile_fail, [''])
test('T14343b', normal, compile_fail, [''])
+test('T15761', normal, compile_fail, [''])