Fix #14681 and #14682 with precision-aimed parentheses ghc-8.4.1-alpha2
authorRyan Scott <ryan.gl.scott@gmail.com>
Thu, 18 Jan 2018 16:06:42 +0000 (11:06 -0500)
committerBen Gamari <ben@smart-cactus.org>
Thu, 18 Jan 2018 19:20:28 +0000 (14:20 -0500)
commit33e3b3eb55cb6cfa4abc7f57581066779a046626
tree62f276cd6452952cd968c8a6b100734f22d14eaf
parent4eccca7e298c08a35f099bd146aedaaf2b853dcf
Fix #14681 and #14682 with precision-aimed parentheses

It turns out that `Convert` was recklessly leaving off
parentheses in two places:

* Negative numeric literals
* Patterns in lambda position

This patch fixes it by adding three new functions, `isCompoundHsLit`,
`isCompoundHsOverLit`, and `isCompoundPat`, and using them in the
right places in `Convert`. While I was in town, I also sprinkled
`isCompoundPat` among some `Pat`-constructing functions in `HsUtils`
to help avoid the likelihood of this problem happening in other
places. One of these places is in `TcGenDeriv`, and sprinkling
`isCompountPat` there fixes #14682

Test Plan: make test TEST="T14681 T14682"

Reviewers: alanz, goldfire, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14681, #14682

Differential Revision: https://phabricator.haskell.org/D4323

(cherry picked from commit 575c009d9e4b25384ef984c09b2c54f909693e93)
12 files changed:
compiler/hsSyn/Convert.hs
compiler/hsSyn/HsLit.hs
compiler/hsSyn/HsPat.hs
compiler/hsSyn/HsTypes.hs
compiler/hsSyn/HsUtils.hs
compiler/typecheck/TcGenDeriv.hs
testsuite/tests/deriving/should_compile/T14682.hs [new file with mode: 0644]
testsuite/tests/deriving/should_compile/T14682.stderr [new file with mode: 0644]
testsuite/tests/deriving/should_compile/all.T
testsuite/tests/th/T14681.hs [new file with mode: 0644]
testsuite/tests/th/T14681.stderr [new file with mode: 0644]
testsuite/tests/th/all.T