Commit 92925b3d authored by Ryan Scott's avatar Ryan Scott Committed by Ben Gamari
Browse files

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

(cherry picked from commit 59a15a56)
parent 9bcbb222
......@@ -500,7 +500,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)
......
......@@ -7,10 +7,10 @@ Derived class instances:
= GHC.Prim.coerce
@(forall (a :: TYPE GHC.Types.LiftedRep)
(b :: TYPE GHC.Types.LiftedRep).
a -> b -> f a -> f b)
(a -> b) -> f a -> f b)
@(forall (a :: TYPE GHC.Types.LiftedRep)
(b :: TYPE GHC.Types.LiftedRep).
a -> b -> T14578.App f a -> T14578.App f b)
(a -> b) -> T14578.App f a -> T14578.App f b)
GHC.Base.fmap
(GHC.Base.<$)
= GHC.Prim.coerce
......@@ -43,11 +43,12 @@ Derived class instances:
@(forall (a :: TYPE GHC.Types.LiftedRep)
(b :: TYPE GHC.Types.LiftedRep)
(c :: TYPE GHC.Types.LiftedRep).
a -> b -> c -> f a -> f b -> f c)
(a -> b -> c) -> f a -> f b -> f c)
@(forall (a :: TYPE GHC.Types.LiftedRep)
(b :: TYPE GHC.Types.LiftedRep)
(c :: TYPE GHC.Types.LiftedRep).
a -> b -> c -> T14578.App f a -> T14578.App f b -> T14578.App f c)
(a -> b -> c)
-> T14578.App f a -> T14578.App f b -> T14578.App f c)
GHC.Base.liftA2
(GHC.Base.*>)
= GHC.Prim.coerce
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment