diff options
author | Leif Metcalf <me@leif.nz> | 2021-01-17 19:36:00 +1300 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-02-22 18:26:54 -0500 |
commit | 22ef7ab10097f92a71369ea99f2f24deea6be080 (patch) | |
tree | e1c01117937580827f403b499311c9674ed67735 /ghc/GHCi | |
parent | b068103d60fd67708916ca5e778f5f833fcc34da (diff) | |
download | haskell-22ef7ab10097f92a71369ea99f2f24deea6be080.tar.gz |
GHCi: Always show fixity
We used to only show the fixity of an operator if it wasn't the default
fixity. Usually this was when the fixity was undeclared, but it could
also arise if one declared the fixity of an operator as infixl 9, the
default fixity. This commit makes it so that :i always shows the fixity
of an operator, even if it is unset.
We may want in the future to keep track of whether an operator's fixity
is defined, so that we can print a comment like
infixl 9 # -- Assumed, since no fixity is declared.
for operators with no specified fixity, and so that we can print fixity
of a term with a non-symbolic term when its fixity has been manually
specified as infixl 9.
Implements #19200.
Diffstat (limited to 'ghc/GHCi')
-rw-r--r-- | ghc/GHCi/UI.hs | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs index 18a6e6eeae..d48bf467f5 100644 --- a/ghc/GHCi/UI.hs +++ b/ghc/GHCi/UI.hs @@ -1552,13 +1552,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 @@ -3264,11 +3260,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 () @@ -4407,6 +4399,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 |