Fix problem of do notation as left argument of an operator

remotes/felixonmars/travis
Lennart Spitzner 2020-04-21 01:34:31 +02:00
parent 86c25ff315
commit 5c64928972
2 changed files with 27 additions and 14 deletions

View File

@ -877,3 +877,10 @@ instance HasDependencies SomeDataModel where
-- between these data models or whatever. -- between these data models or whatever.
type Dependencies SomeDataModel type Dependencies SomeDataModel
= (SomeOtherDataModelId, SomeOtherOtherDataModelId) = (SomeOtherDataModelId, SomeOtherOtherDataModelId)
#test stupid-do-operator-combination
func =
do
y
>>= x

View File

@ -426,6 +426,9 @@ layoutExpr lexpr@(L _ expr) = do
(_, L _ (HsApp _ (L _ HsVar{}))) -> False (_, L _ (HsApp _ (L _ HsVar{}))) -> False
_ -> True _ -> True
#endif #endif
let leftIsDoBlock = case expLeft of
L _ HsDo{} -> True
_ -> False
runFilteredAlternative $ do runFilteredAlternative $ do
-- one-line -- one-line
addAlternative addAlternative
@ -442,16 +445,17 @@ layoutExpr lexpr@(L _ expr) = do
-- , docSetBaseY $ docAddBaseY BrIndentRegular expDocRight -- , docSetBaseY $ docAddBaseY BrIndentRegular expDocRight
-- ] -- ]
-- two-line -- two-line
addAlternative addAlternative $ do
$ docAddBaseY BrIndentRegular let
$ docPar expDocOpAndRight = docForceSingleline
expDocLeft -- TODO: this is not forced to single-line, which has $ docCols ColOpPrefix [appSep $ expDocOp, docSetBaseY expDocRight]
-- certain.. interesting consequences. if leftIsDoBlock
then docLines [expDocLeft, expDocOpAndRight]
else docAddBaseY BrIndentRegular $ docPar expDocLeft expDocOpAndRight
-- TODO: in both cases, we don't force expDocLeft to be
-- single-line, which has certain.. interesting consequences.
-- At least, the "two-line" label is not entirely -- At least, the "two-line" label is not entirely
-- accurate. -- accurate.
( docForceSingleline
$ docCols ColOpPrefix [appSep $ expDocOp, docSetBaseY expDocRight]
)
-- one-line + par -- one-line + par
addAlternativeCond allowPar addAlternativeCond allowPar
$ docSeq $ docSeq
@ -460,11 +464,13 @@ layoutExpr lexpr@(L _ expr) = do
, docForceParSpacing expDocRight , docForceParSpacing expDocRight
] ]
-- more lines -- more lines
addAlternative addAlternative $ do
$ docAddBaseY BrIndentRegular let expDocOpAndRight =
$ docPar docCols ColOpPrefix [appSep expDocOp, docSetBaseY expDocRight]
expDocLeft if leftIsDoBlock
(docCols ColOpPrefix [appSep expDocOp, docSetBaseY expDocRight]) then docLines [expDocLeft, expDocOpAndRight]
else docAddBaseY BrIndentRegular
$ docPar expDocLeft expDocOpAndRight
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
NegApp _ op _ -> do NegApp _ op _ -> do
#else #else