[Git][ghc/ghc][ghc-8.8] Use funPrec, not topPrec, to parenthesize GADT argument types
Ben Gamari
gitlab at gitlab.haskell.org
Thu Apr 11 23:13:28 UTC 2019
Ben Gamari pushed to branch ghc-8.8 at Glasgow Haskell Compiler / GHC
Commits:
20f8f2f9 by Ryan Scott at 2019-04-09T20:21:35Z
Use funPrec, not topPrec, to parenthesize GADT argument types
A simple oversight. Fixes #16527.
- - - - -
5 changed files:
- compiler/iface/IfaceSyn.hs
- + testsuite/tests/ghci/scripts/T16527.hs
- + testsuite/tests/ghci/scripts/T16527.script
- + testsuite/tests/ghci/scripts/T16527.stdout
- testsuite/tests/ghci/scripts/all.T
Changes:
=====================================
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
=====================================
testsuite/tests/ghci/scripts/T16527.hs
=====================================
@@ -0,0 +1,7 @@
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE RankNTypes #-}
+module T16527 where
+
+data T where
+ MkT1 :: (Int -> Int) -> T
+ MkT2 :: (forall a. Maybe a) -> T
=====================================
testsuite/tests/ghci/scripts/T16527.script
=====================================
@@ -0,0 +1,2 @@
+:load T16527
+:info T
=====================================
testsuite/tests/ghci/scripts/T16527.stdout
=====================================
@@ -0,0 +1,4 @@
+data T where
+ MkT1 :: (Int -> Int) -> T
+ MkT2 :: (forall a. Maybe a) -> T
+ -- Defined at T16527.hs:5:1
=====================================
testsuite/tests/ghci/scripts/all.T
=====================================
@@ -295,3 +295,4 @@ test('T15941', normal, ghci_script, ['T15941.script'])
test('T16030', normal, ghci_script, ['T16030.script'])
test('T11606', normal, ghci_script, ['T11606.script'])
test('T16089', normal, ghci_script, ['T16089.script'])
+test('T16527', normal, ghci_script, ['T16527.script'])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/20f8f2f98bd686b297e7290b2348ac7e937c1a5a
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/20f8f2f98bd686b297e7290b2348ac7e937c1a5a
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20190411/1eece06e/attachment-0001.html>
More information about the ghc-commits
mailing list