diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2019-04-03 12:37:10 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-04-04 04:35:39 -0400 |
commit | 51fd357119b357c52e990ccce9059c423cc49406 (patch) | |
tree | f7c597ea5034d7500c49930d50b92446580a0356 /compiler/iface | |
parent | 25c02ea172ef1dad2d12d8baff6ce57a68bf4127 (diff) | |
download | haskell-51fd357119b357c52e990ccce9059c423cc49406.tar.gz |
Use funPrec, not topPrec, to parenthesize GADT argument types
A simple oversight. Fixes #16527.
Diffstat (limited to 'compiler/iface')
-rw-r--r-- | compiler/iface/IfaceSyn.hs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/compiler/iface/IfaceSyn.hs b/compiler/iface/IfaceSyn.hs index 8ffa337946..f284ae9373 100644 --- a/compiler/iface/IfaceSyn.hs +++ b/compiler/iface/IfaceSyn.hs @@ -1034,7 +1034,7 @@ pprIfaceConDecl ss gadt_style tycon tc_binders parent -- a compound field type is if it's preceded by a bang pattern. pprFieldArgTy (bang, ty) = ppr_arg_ty (bang_prec bang) bang ty -- If not using record syntax, a compound field type might need to be - -- parenthesize if one of the following holds: + -- parenthesized if one of the following holds: -- -- 1. We're using Haskell98 syntax. -- 2. The field type is preceded with a bang pattern. @@ -1046,18 +1046,23 @@ pprIfaceConDecl ss gadt_style tycon tc_binders parent -- If we're displaying the fields GADT-style, e.g., -- -- data Foo a where - -- MkFoo :: Maybe a -> Foo + -- MkFoo :: (Int -> Int) -> Maybe a -> Foo -- - -- Then there is no inherent need to parenthesize compound fields like - -- `Maybe a` (bang patterns notwithstanding). If we're displaying the - -- fields Haskell98-style, e.g., + -- Then we use `funPrec`, since that will ensure `Int -> Int` gets the + -- parentheses that it requires, but simple compound types like `Maybe a` + -- (which don't require parentheses in a function argument position) won't + -- get them, assuming that there are no bang patterns (see bang_prec). -- - -- data Foo a = MkFoo (Maybe a) + -- If we're displaying the fields Haskell98-style, e.g., -- - -- Then we *must* parenthesize compound fields like (Maybe a). + -- data Foo a = MkFoo (Int -> Int) (Maybe a) + -- + -- Then not only must we parenthesize `Int -> Int`, we must also + -- parenthesize compound fields like (Maybe a). Therefore, we pick + -- `appPrec`, which has higher precedence than `funPrec`. gadt_prec :: PprPrec gadt_prec - | gadt_style = topPrec + | gadt_style = funPrec | otherwise = appPrec -- The presence of bang patterns or UNPACK annotations requires |