diff options
author | jackohughes <jack@jackohughes.com> | 2022-04-11 19:41:02 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-05-13 12:10:34 -0400 |
commit | 668a9ef496f9df7e628397c4de9a0a4fcdcd7e6a (patch) | |
tree | 11a79dacda0b6c7cf550dc5c6d34af82fa965620 /compiler/GHC/Iface | |
parent | 3bf938b6c5e1190f3a55e149deaec2f6309d398f (diff) | |
download | haskell-668a9ef496f9df7e628397c4de9a0a4fcdcd7e6a.tar.gz |
Fix printing of brackets in multiplicities (#20315)
Change mulArrow to allow for printing of correct application precedence
where necessary and update callers of mulArrow to reflect this.
As part of this, move mulArrow from GHC/Utils/Outputtable to GHC/Iface/Type.
Fixes #20315
Diffstat (limited to 'compiler/GHC/Iface')
-rw-r--r-- | compiler/GHC/Iface/Type.hs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/compiler/GHC/Iface/Type.hs b/compiler/GHC/Iface/Type.hs index 40dccb6e0e..cb50003fe4 100644 --- a/compiler/GHC/Iface/Type.hs +++ b/compiler/GHC/Iface/Type.hs @@ -55,6 +55,7 @@ module GHC.Iface.Type ( pprIfaceCoercion, pprParendIfaceCoercion, splitIfaceSigmaTy, pprIfaceTypeApp, pprUserIfaceForAll, pprIfaceCoTcApp, pprTyTcApp, pprIfacePrefixApp, + mulArrow, ppr_fun_arrow, isIfaceTauType, @@ -909,13 +910,19 @@ pprPrecIfaceType :: PprPrec -> IfaceType -> SDoc pprPrecIfaceType prec ty = hideNonStandardTypes (ppr_ty prec) ty +-- mulArrow takes a pretty printer for the type it is being called on to +-- allow type applications to be printed with the correct precedence inside +-- the multiplicity e.g. a %(m n) -> b. See #20315. +mulArrow :: (PprPrec -> a -> SDoc) -> a -> SDoc +mulArrow ppr_mult mult = text "%" <> ppr_mult appPrec mult <+> arrow + ppr_fun_arrow :: IfaceMult -> SDoc ppr_fun_arrow w | (IfaceTyConApp tc _) <- w , tc `ifaceTyConHasKey` (getUnique manyDataConTyCon) = arrow | (IfaceTyConApp tc _) <- w , tc `ifaceTyConHasKey` (getUnique oneDataConTyCon) = lollipop - | otherwise = mulArrow (pprIfaceType w) + | otherwise = mulArrow pprPrecIfaceType w ppr_sigma :: PprPrec -> IfaceType -> SDoc ppr_sigma ctxt_prec ty @@ -1718,7 +1725,7 @@ ppr_co ctxt_prec (IfaceFunCo r cow co1 co2) = (coercionArrow cow' <> ppr_role r <+> ppr_co funPrec co1) : ppr_fun_tail cow co2 ppr_fun_tail cow' other_co = [coercionArrow cow' <> ppr_role r <+> pprIfaceCoercion other_co] - coercionArrow w = mulArrow (ppr_co topPrec w) + coercionArrow w = mulArrow ppr_co w ppr_co _ (IfaceTyConAppCo r tc cos) = parens (pprIfaceCoTcApp topPrec tc cos) <> ppr_role r |