diff options
author | Richard Eisenberg <rae@cs.brynmawr.edu> | 2018-10-17 10:46:21 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-10-17 14:46:22 -0400 |
commit | ba5d0a4812a1437b11cacc53cc1a4024db6ad160 (patch) | |
tree | 2b7557713de3d08e38a3b2e1d99e76598abd2ce9 | |
parent | 334be779756a54028c5b83cd89c4665e946c65ea (diff) | |
download | haskell-ba5d0a4812a1437b11cacc53cc1a4024db6ad160.tar.gz |
Fix #15761 by adding parens
This was just a pretty-printer infelicity. Fixed now.
Test case: printer/T15761
(cherry picked from commit 38c28c1a8bb129141e533866700e7318314f32c1)
-rw-r--r-- | compiler/hsSyn/HsDecls.hs | 16 | ||||
-rw-r--r-- | testsuite/tests/printer/T15761.hs | 5 | ||||
-rw-r--r-- | testsuite/tests/printer/T15761.stderr | 5 | ||||
-rw-r--r-- | testsuite/tests/printer/all.T | 1 |
4 files changed, 20 insertions, 7 deletions
diff --git a/compiler/hsSyn/HsDecls.hs b/compiler/hsSyn/HsDecls.hs index 277a6d3240..f84fcfd5ec 100644 --- a/compiler/hsSyn/HsDecls.hs +++ b/compiler/hsSyn/HsDecls.hs @@ -1713,13 +1713,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, ['']) |