summaryrefslogtreecommitdiff
path: root/compiler/hsSyn/Convert.hs
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2018-10-28 16:08:11 -0400
committerBen Gamari <ben@smart-cactus.org>2018-10-29 15:10:24 -0400
commitb8a797ecc34a309bd78f5a290e3554642a3a478a (patch)
tree709eb34845e0df4ddea48d4626132e9a0c300522 /compiler/hsSyn/Convert.hs
parent331081b03f67c94b908136339aebf36d07d45c21 (diff)
downloadhaskell-b8a797ecc34a309bd78f5a290e3554642a3a478a.tar.gz
Fix #15815 by parenthesizing the arguments to infix ~
An unfortunate consequence of commit b9483981d128f55d8dae3f434f49fa6b5b30c779 (`Remove HsEqTy and XEqTy`) is infix uses of `~` in TH quotes now desugar differently than before. In particular, we have that: ```haskell a ~ (Int -> Int) ``` Now desugars to: ```haskell HsOpTy a (~) (HsOpTy Int (->) Int) ``` Which GHC interprets as being: ```haskell a ~ Int -> Int ``` Or, equivalently: ```haskell (a ~ Int) -> Int ``` Which is different than what was intended! This is the cause of #15815. All of this has revealed that we likely need to renovate the way we desugar infix type operators to be more consistent with the treatment for infix expressions (see https://ghc.haskell.org/trac/ghc/ticket/15815#comment:5 for more on this.) Doing so would constitute a breaking change, however, so we will likely want to wait until another major GHC release to do this. In the meantime, this patch offers a non-invasive change to the way that infix uses of `~` are desugared. This makes the program in #15815 compile again by inserting extra `HsParTy`s around the arguments to `~` if they are lacking them. Test Plan: make test TEST=T15815 Reviewers: int-index, goldfire, bgamari Reviewed By: int-index Subscribers: int-e, rwbarton, carter GHC Trac Issues: #15815 Differential Revision: https://phabricator.haskell.org/D5274
Diffstat (limited to 'compiler/hsSyn/Convert.hs')
-rw-r--r--compiler/hsSyn/Convert.hs8
1 files changed, 7 insertions, 1 deletions
diff --git a/compiler/hsSyn/Convert.hs b/compiler/hsSyn/Convert.hs
index 8b12a78ed3..06d5d6ca7a 100644
--- a/compiler/hsSyn/Convert.hs
+++ b/compiler/hsSyn/Convert.hs
@@ -1437,7 +1437,13 @@ cvtTypeKind ty_str ty
EqualityT
| [x',y'] <- tys' ->
- returnL (HsOpTy noExt x' (noLoc eqTyCon_RDR) y')
+ let px = parenthesizeHsType opPrec x'
+ py = parenthesizeHsType opPrec y'
+ in returnL (HsOpTy noExt px (noLoc eqTyCon_RDR) py)
+ -- The long-term goal is to remove the above case entirely and
+ -- subsume it under the case for InfixT. See #15815, comment:6,
+ -- for more details.
+
| otherwise ->
mk_apps (HsTyVar noExt NotPromoted
(noLoc eqTyCon_RDR)) tys'