diff options
author | Vladislav Zavialov <vlad.z.4096@gmail.com> | 2022-10-28 00:28:07 +0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-11-01 12:49:10 -0400 |
commit | 30e625e6d4bdd15960edce8ecc40b85ce3d72b28 (patch) | |
tree | a661f2fe5c5f278480d02edd885c08f3fd2ebc01 /compiler/GHC/ThToHs.hs | |
parent | b7a001132202e1ebf03dd21c6c7b4cd7a24df501 (diff) | |
download | haskell-30e625e6d4bdd15960edce8ecc40b85ce3d72b28.tar.gz |
ThToHs: fix overzealous parenthesization
Before this patch, when converting from TH.Exp to LHsExpr GhcPs,
the compiler inserted more parentheses than required:
((f a) (b + c)) d
This was happening because the LHS of the function application was
parenthesized as if it was the RHS.
Now we use funPrec and appPrec appropriately and produce sensibly
parenthesized expressions:
f a (b + c) d
I also took the opportunity to remove the special case for LamE,
which was not special at all and simply duplicated code.
Diffstat (limited to 'compiler/GHC/ThToHs.hs')
-rw-r--r-- | compiler/GHC/ThToHs.hs | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/compiler/GHC/ThToHs.hs b/compiler/GHC/ThToHs.hs index 9f5badae49..11f601cd70 100644 --- a/compiler/GHC/ThToHs.hs +++ b/compiler/GHC/ThToHs.hs @@ -979,17 +979,13 @@ cvtl e = wrapLA (cvt e) l' <- cvt_lit l let e' = mk_expr l' if is_compound_lit l' then wrapParLA gHsPar e' else pure e' - cvt (AppE x@(LamE _ _) y) = do { x' <- cvtl x; y' <- cvtl y - ; return $ HsApp noComments (mkLHsPar x') - (mkLHsPar y')} - cvt (AppE x y) = do { x' <- cvtl x; y' <- cvtl y - ; return $ HsApp noComments (mkLHsPar x') - (mkLHsPar y')} - cvt (AppTypeE e t) = do { e' <- cvtl e - ; t' <- cvtType t - ; let tp = parenthesizeHsType appPrec t' + cvt (AppE e1 e2) = do { e1' <- parenthesizeHsExpr opPrec <$> cvtl e1 + ; e2' <- parenthesizeHsExpr appPrec <$> cvtl e2 + ; return $ HsApp noComments e1' e2' } + cvt (AppTypeE e t) = do { e' <- parenthesizeHsExpr opPrec <$> cvtl e + ; t' <- parenthesizeHsType appPrec <$> cvtType t ; return $ HsAppType noExtField e' noHsTok - $ mkHsWildCardBndrs tp } + $ mkHsWildCardBndrs t' } cvt (LamE [] e) = cvt e -- Degenerate case. We convert the body as its -- own expression to avoid pretty-printing -- oddities that can result from zero-argument |