diff --git a/data/examples/declaration/value/function/operator-sections-out.hs b/data/examples/declaration/value/function/operator-sections-out.hs index bfa62d8..fabdf77 100644 --- a/data/examples/declaration/value/function/operator-sections-out.hs +++ b/data/examples/declaration/value/function/operator-sections-out.hs @@ -9,3 +9,5 @@ baz = ( * 3 ^ 5 ) + +quux = (,) <$> foo <$> bar diff --git a/data/examples/declaration/value/function/operator-sections.hs b/data/examples/declaration/value/function/operator-sections.hs index e0e375d..3fd6f55 100644 --- a/data/examples/declaration/value/function/operator-sections.hs +++ b/data/examples/declaration/value/function/operator-sections.hs @@ -5,3 +5,5 @@ baz = + ) ( * 3 ^ 5) + +quux = (,) <$> foo <$> bar diff --git a/src/Ormolu/Printer/Meat/Common.hs b/src/Ormolu/Printer/Meat/Common.hs index 2eff839..2668d0e 100644 --- a/src/Ormolu/Printer/Meat/Common.hs +++ b/src/Ormolu/Printer/Meat/Common.hs @@ -56,7 +56,7 @@ p_rdrName l@(L spn _) = located l $ \x -> do if AnnOpenP `elem` ids then parens else id - (m, isUnit) = + (m, avoidParens) = case x of Unqual occName -> (atom occName, False) @@ -68,8 +68,8 @@ p_rdrName l@(L spn _) = located l $ \x -> do -- NOTE I'm not sure this "stable string" is stable enough, but -- it looks like this is the most robust way to tell if we're -- looking at exactly this piece of built-in syntax. - (atom name, nameStableString name == "$ghc-prim$GHC.Tuple$()") - if isUnit + (atom name, nameStableString name `elem` avoidParensStableNames) + if avoidParens then m else parensWrapper (backticksWrapper m) @@ -83,3 +83,13 @@ p_ieWildcard :: IEWildcard -> R () p_ieWildcard = \case NoIEWildcard -> return () IEWildcard n -> parens (atom n) + +avoidParensStableNames :: [String] +avoidParensStableNames = + [ "$ghc-prim$GHC.Tuple$()" + , "$ghc-prim$GHC.Tuple$(,)" + , "$ghc-prim$GHC.Tuple$(,,)" + , "$ghc-prim$GHC.Tuple$(,,,)" + , "$ghc-prim$GHC.Tuple$(,,,,)" + , "$ghc-prim$GHC.Tuple$(,,,,,)" + ]