Fix #15307 by making nlHsFunTy parenthesize more
authorRyan Scott <ryan.gl.scott@gmail.com>
Thu, 5 Jul 2018 12:29:59 +0000 (08:29 -0400)
committerRyan Scott <ryan.gl.scott@gmail.com>
Thu, 5 Jul 2018 12:29:59 +0000 (08:29 -0400)
commit59a15a56e180b59656e45df04f7df61de8298881
tree857ac6a5d459281ac567a5b9b34e61fcbdf4b7d9
parent45f44e2c9d5db2f25c52abb402f197c20579400f
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
compiler/hsSyn/HsUtils.hs
testsuite/tests/deriving/should_compile/T14578.stderr