summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ghc/GHCi/UI.hs30
-rw-r--r--testsuite/tests/ghci/scripts/T6027ghci.stdout1
-rw-r--r--testsuite/tests/ghci/scripts/ghci012.stdout1
3 files changed, 22 insertions, 10 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index f78faae40d..4a382f74da 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -1535,13 +1535,9 @@ pprInfo :: (TyThing, Fixity, [GHC.ClsInst], [GHC.FamInst], SDoc) -> SDoc
pprInfo (thing, fixity, cls_insts, fam_insts, docs)
= docs
$$ pprTyThingInContextLoc thing
- $$ show_fixity
+ $$ showFixity thing fixity
$$ vcat (map GHC.pprInstance cls_insts)
$$ vcat (map GHC.pprFamInst fam_insts)
- where
- show_fixity
- | fixity == GHC.defaultFixity = empty
- | otherwise = ppr fixity <+> pprInfixName (GHC.getName thing)
-----------------------------------------------------------------------------
-- :main
@@ -3202,11 +3198,7 @@ showBindings = do
pprTT :: (TyThing, Fixity, [GHC.ClsInst], [GHC.FamInst], SDoc) -> SDoc
pprTT (thing, fixity, _cls_insts, _fam_insts, _docs)
= pprTyThing showToHeader thing
- $$ show_fixity
- where
- show_fixity
- | fixity == GHC.defaultFixity = empty
- | otherwise = ppr fixity <+> ppr (GHC.getName thing)
+ $$ showFixity thing fixity
printTyThing :: GHC.GhcMonad m => TyThing -> m ()
@@ -4336,6 +4328,24 @@ showModule = moduleNameString . moduleName
declPath :: [String] -> String
declPath = intercalate "."
+-- | Optionally show a fixity declaration like @infixr 4 #@
+--
+-- We always display the fixity of terms with symbolic names (like <$>).
+-- For other terms we only display the fixity if it has been set to a
+-- value other than the default infixl 9.
+--
+-- We have no way of distinguishing between a fixity that has been
+-- manually set to infixl 9 and a fixity that has assumed infixl 9 as
+-- the default, so we choose to not display the fixity in both cases
+-- (for terms with non-symbolic names).
+--
+-- See #19200.
+showFixity :: TyThing -> Fixity -> SDoc
+showFixity thing fixity
+ | fixity /= GHC.defaultFixity || isSymOcc (getOccName thing)
+ = ppr fixity <+> pprInfixName (GHC.getName thing)
+ | otherwise = empty
+
-- TODO: won't work if home dir is encoded.
-- (changeDirectory may not work either in that case.)
expandPath :: MonadIO m => String -> m String
diff --git a/testsuite/tests/ghci/scripts/T6027ghci.stdout b/testsuite/tests/ghci/scripts/T6027ghci.stdout
index 7711a3003f..a3afcf2035 100644
--- a/testsuite/tests/ghci/scripts/T6027ghci.stdout
+++ b/testsuite/tests/ghci/scripts/T6027ghci.stdout
@@ -1,3 +1,4 @@
type (?) :: *
data (?)
-- Defined at <interactive>:2:1
+infixl 9 ?
diff --git a/testsuite/tests/ghci/scripts/ghci012.stdout b/testsuite/tests/ghci/scripts/ghci012.stdout
index 32ceac8b06..c4d2cbdc2b 100644
--- a/testsuite/tests/ghci/scripts/ghci012.stdout
+++ b/testsuite/tests/ghci/scripts/ghci012.stdout
@@ -1 +1,2 @@
($$$) :: [b -> c] -> [b] -> [c] -- Defined at <interactive>:1:8
+infixl 9 $$$