diff --git a/CHANGELOG.md b/CHANGELOG.md index d9290eabd..454e54b07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Fix the bug of wrongly converting a `newtype` instance to a `data` one ([#839]) - Fix the bug of not pretty-printing multiple functional dependencies in a typeclass ([#843]) - Fix the bug of not pretty-printing data declarations with records and typeclass constraints ([#849]) +- Fix the bug of not pretty-printing unboxed tuples ([#868]) ### Removed @@ -374,6 +375,7 @@ This version is accidentally pushlished, and is the same as 5.3.3. [@uhbif19]: https://github.com/uhbif19 [@toku-sa-n]: https://github.com/toku-sa-n +[#868]: https://github.com/mihaimaruseac/hindent/pull/868 [#849]: https://github.com/mihaimaruseac/hindent/pull/849 [#843]: https://github.com/mihaimaruseac/hindent/pull/843 [#839]: https://github.com/mihaimaruseac/hindent/pull/839 diff --git a/TESTS.md b/TESTS.md index 49769d405..22a5f7759 100644 --- a/TESTS.md +++ b/TESTS.md @@ -2831,6 +2831,17 @@ Unboxed `String` a = "Foo"# ``` +`UnboxedTuple` + +```haskell +{-# LANGUAGE UnboxedTuples #-} + +f :: (# Int, Int #) -> (# Int, Int #) +f t = + case t of + (# x, y #) -> (# x, y #) +``` + `NumericUnderscores` ```haskell diff --git a/src/HIndent/Pretty.hs b/src/HIndent/Pretty.hs index 40db999c4..d718de4fe 100644 --- a/src/HIndent/Pretty.hs +++ b/src/HIndent/Pretty.hs @@ -244,15 +244,23 @@ prettyHsExpr (GHC.HsPar _ expr) = parens $ pretty expr #endif prettyHsExpr (GHC.SectionL _ l o) = spaced [pretty l, pretty (InfixExpr o)] prettyHsExpr (GHC.SectionR _ o r) = (pretty (InfixExpr o) >> space) |=> pretty r -prettyHsExpr (GHC.ExplicitTuple _ full _) = horizontal <-|> vertical +prettyHsExpr (GHC.ExplicitTuple _ full boxity) = horizontal <-|> vertical where - horizontal = hTuple $ fmap pretty full + horizontal = parH $ fmap pretty full vertical = - parens + parV $ prefixedLined "," $ fmap (\e -> unless (isMissing e) (space |=> pretty e)) full isMissing GHC.Missing {} = True isMissing _ = False + parH = + case boxity of + GHC.Boxed -> hTuple + GHC.Unboxed -> hUnboxedTuple + parV = + case boxity of + GHC.Boxed -> parens + GHC.Unboxed -> unboxedParens prettyHsExpr (GHC.ExplicitSum _ position numElem expr) = do string "(#" forM_ [1 .. numElem] $ \idx -> do