Fix lambdas with lazy/bang pattern as first argument

remotes/felixonmars/release
Lennart Spitzner 2019-09-03 01:04:25 +02:00
parent 702b993dab
commit 6879436e67
2 changed files with 29 additions and 1 deletions

View File

@ -672,3 +672,11 @@ _ `nor` _ = False
#test issue 256 prefix operator match #test issue 256 prefix operator match
f ((:) a as) = undefined f ((:) a as) = undefined
#test issue 228 lambda plus lazy or bang pattern
{-# LANGUAGE BangPatterns #-}
a = \x -> x
b = \ ~x -> x
c = \ !x -> x
d = \(~x) -> x

View File

@ -101,7 +101,27 @@ layoutExpr lexpr@(L _ expr) = do
, L _ (GRHS [] body) <- lgrhs , L _ (GRHS [] body) <- lgrhs
#endif #endif
-> do -> do
patDocs <- pats `forM` \p -> fmap return $ colsWrapPat =<< layoutPat p patDocs <- zip (True : repeat False) pats `forM` \(isFirst, p) ->
fmap return $ do
-- this code could be as simple as `colsWrapPat =<< layoutPat p`
-- if it was not for the following two cases:
-- \ !x -> x
-- \ ~x -> x
-- These make it necessary to special-case an additional separator.
-- (TODO: we create a BDCols here, but then make it ineffective
-- by wrapping it in docSeq below. We _could_ add alignments for
-- stuff like lists-of-lambdas. Nothing terribly important..)
let shouldPrefixSeparator = case p of
(L _ LazyPat{}) -> isFirst
(L _ BangPat{}) -> isFirst
_ -> False
patDocSeq <- layoutPat p
fixed <- case Seq.viewl patDocSeq of
p1 Seq.:< pr | shouldPrefixSeparator -> do
p1' <- docSeq [docSeparator, pure p1]
pure (p1' Seq.<| pr)
_ -> pure patDocSeq
colsWrapPat fixed
bodyDoc <- docAddBaseY BrIndentRegular <$> docSharedWrapper layoutExpr body bodyDoc <- docAddBaseY BrIndentRegular <$> docSharedWrapper layoutExpr body
let funcPatternPartLine = let funcPatternPartLine =
docCols ColCasePattern docCols ColCasePattern