summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2018-07-05 08:29:59 -0400
committerRyan Scott <ryan.gl.scott@gmail.com>2018-07-05 08:29:59 -0400
commit59a15a56e180b59656e45df04f7df61de8298881 (patch)
tree857ac6a5d459281ac567a5b9b34e61fcbdf4b7d9 /compiler
parent45f44e2c9d5db2f25c52abb402f197c20579400f (diff)
downloadhaskell-59a15a56e180b59656e45df04f7df61de8298881.tar.gz
Fix #15307 by making nlHsFunTy parenthesize more
Summary: `nlHsFunTy` wasn't parenthesizing its arguments at all, which led to `-ddump-deriv` producing incorrectly parenthesized types (since it uses `nlHsFunTy` to construct those types), as demonstrated in #15307. Fix this by changing `nlHsFunTy` to add parentheses à la `ppr_ty`: always parenthesizing the argument type with function precedence, and recursively processing the result type, adding parentheses for each function type it encounters. Test Plan: make test TEST=T14578 Reviewers: bgamari Reviewed By: bgamari Subscribers: rwbarton, thomie, carter GHC Trac Issues: #15307 Differential Revision: https://phabricator.haskell.org/D4890
Diffstat (limited to 'compiler')
-rw-r--r--compiler/hsSyn/HsUtils.hs8
1 files changed, 7 insertions, 1 deletions
diff --git a/compiler/hsSyn/HsUtils.hs b/compiler/hsSyn/HsUtils.hs
index e8e59b001b..9a66b4a0b0 100644
--- a/compiler/hsSyn/HsUtils.hs
+++ b/compiler/hsSyn/HsUtils.hs
@@ -497,7 +497,13 @@ nlHsParTy :: LHsType (GhcPass p) -> LHsType (GhcPass p)
nlHsAppTy f t = noLoc (HsAppTy noExt f (parenthesizeHsType appPrec t))
nlHsTyVar x = noLoc (HsTyVar noExt NotPromoted (noLoc x))
-nlHsFunTy a b = noLoc (HsFunTy noExt a b)
+nlHsFunTy a b = noLoc (HsFunTy noExt (parenthesizeHsType funPrec a)
+ (parenthesize_fun_tail b))
+ where
+ parenthesize_fun_tail (L loc (HsFunTy ext ty1 ty2))
+ = L loc (HsFunTy ext (parenthesizeHsType funPrec ty1)
+ (parenthesize_fun_tail ty2))
+ parenthesize_fun_tail lty = lty
nlHsParTy t = noLoc (HsParTy noExt t)
nlHsTyConApp :: IdP (GhcPass p) -> [LHsType (GhcPass p)] -> LHsType (GhcPass p)