on master help sign in
Fix rendering of value-level units
e98df37mrkkrp
data/examples/declaration/value/function/builtin-syntax-out.hsnew file+1
@@ -0,0 +1 @@
1+x = return ()
data/examples/declaration/value/function/builtin-syntax.hsnew file+1
@@ -0,0 +1 @@
1+x = return ()
src/Ormolu/Printer/Meat/Common.hs+19−10
@@ -15,10 +15,10 @@ where
15
15
16import GHC hiding (GhcPs, IE)
16import GHC hiding (GhcPs, IE)
17import Module (Module (..))
17import Module (Module (..))
18+import Name (nameStableString)
18import OccName (OccName (..))
19import OccName (OccName (..))
19import Ormolu.Printer.Combinators
20import Ormolu.Printer.Combinators
20import Ormolu.Printer.Internal (getAnns)
21import Ormolu.Printer.Internal (getAnns)
21−import Ormolu.Utils (getSpan)
22import RdrName (RdrName (..))
22import RdrName (RdrName (..))
23
23
24-- | Data and type family style.
24-- | Data and type family style.
@@ -45,8 +45,8 @@ p_ieWrappedName = \case
45-- | Render a @'Located' 'RdrName'@.
45-- | Render a @'Located' 'RdrName'@.
46
46
47p_rdrName :: Located RdrName -> R ()
47p_rdrName :: Located RdrName -> R ()
48−p_rdrName l = located l $ \x -> do
48+p_rdrName l@(L spn _) = located l $ \x -> do
49− ids <- getAnns (getSpan l)
49+ ids <- getAnns spn
50 -- NOTE Right now we're mainly interested in backticks and parentheses.
50 -- NOTE Right now we're mainly interested in backticks and parentheses.
51 let backticksWrapper =
51 let backticksWrapper =
52 if AnnBackquote `elem` ids
52 if AnnBackquote `elem` ids
@@ -56,13 +56,22 @@ p_rdrName l = located l $ \x -> do
56 if AnnOpenP `elem` ids
56 if AnnOpenP `elem` ids
57 then parens
57 then parens
58 else id
58 else id
59− -- TODO Check if it's possible to detect simple quoting here as well.
59+ (m, isUnit) =
60− parensWrapper . backticksWrapper $
61− case x of
60+ case x of
62− Unqual occName -> atom occName
61+ Unqual occName ->
62+ (atom occName, False)
63+ Qual mname occName ->
63− Qual mname occName -> p_qualName mname occName
64+ (p_qualName mname occName, False)
64− Orig (Module _ mname) occName -> p_qualName mname occName
65+ Orig (Module _ mname) occName ->
66+ (p_qualName mname occName, False)
65− Exact name -> atom name
67+ Exact name ->
68+ -- NOTE I'm not sure this "stable string" is stable enough, but
69+ -- it looks like this is the most robust way to tell if we're
70+ -- looking at exactly this piece of built-in syntax.
71+ (atom name, nameStableString name == "$ghc-prim$GHC.Tuple$()")
72+ if isUnit
73+ then m
74+ else parensWrapper (backticksWrapper m)
66
75
67p_qualName :: ModuleName -> OccName -> R ()
76p_qualName :: ModuleName -> OccName -> R ()
68p_qualName mname occName = do
77p_qualName mname occName = do