From 655074d1c0f8ac3b13021157a1def3b2d15f60f8 Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Thu, 10 Aug 2017 13:09:39 +0200 Subject: [PATCH] Fix comment insertion error introduced in 91b9a240 --- src-literatetests/tests.blt | 11 ++++++ .../Haskell/Brittany/Internal/Backend.hs | 3 -- .../Haskell/Brittany/Internal/BackendUtils.hs | 37 ++++++++----------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src-literatetests/tests.blt b/src-literatetests/tests.blt index 8d9064e..1f2ab6e 100644 --- a/src-literatetests/tests.blt +++ b/src-literatetests/tests.blt @@ -1006,6 +1006,17 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs = do , let guardPart = singleLineGuardsDoc guards ] +#test comment-testcase-17 +{-# LANGUAGE MultiWayIf #-} +func = do + let foo = if + | Constuctoooooooooooooooooooooooooooooooooooor `elem` artics -- TODO + -> max + (defLen - 0.2) -- TODO + (defLen * 0.8) + | otherwise -> max (defLen - 0.05) (defLen * 0.95) -- TODO + return True + ############################################################################### ############################################################################### diff --git a/src/Language/Haskell/Brittany/Internal/Backend.hs b/src/Language/Haskell/Brittany/Internal/Backend.hs index e9114cc..f0b6403 100644 --- a/src/Language/Haskell/Brittany/Internal/Backend.hs +++ b/src/Language/Haskell/Brittany/Internal/Backend.hs @@ -167,7 +167,6 @@ layoutBriDocM = \case Just [] -> when allowMTEL $ moveToExactAnn annKey Just priors -> do -- layoutResetSepSpace - when (not $ null priors) $ layoutSetCommentCol priors `forM_` \(ExactPrint.Types.Comment comment _ _, ExactPrint.Types.DP (y, x)) -> do @@ -209,7 +208,6 @@ layoutBriDocM = \case case mComments of Nothing -> pure () Just comments -> do - layoutSetCommentCol comments `forM_` \(ExactPrint.Types.Comment comment _ _, ExactPrint.Types.DP (y, x)) -> do -- evil hack for CPP: @@ -241,7 +239,6 @@ layoutBriDocM = \case case mComments of Nothing -> pure () Just comments -> do - layoutSetCommentCol comments `forM_` \(ExactPrint.Types.Comment comment _ _, ExactPrint.Types.DP (y, x)) -> do -- evil hack for CPP: diff --git a/src/Language/Haskell/Brittany/Internal/BackendUtils.hs b/src/Language/Haskell/Brittany/Internal/BackendUtils.hs index c3712b1..a7d8594 100644 --- a/src/Language/Haskell/Brittany/Internal/BackendUtils.hs +++ b/src/Language/Haskell/Brittany/Internal/BackendUtils.hs @@ -184,27 +184,22 @@ layoutMoveToCommentPos layoutMoveToCommentPos y x = do traceLocal ("layoutMoveToCommentPos", y, x) state <- mGet - if Data.Maybe.isJust (_lstate_commentCol state) - then do - mSet state - { _lstate_curYOrAddNewline = case _lstate_curYOrAddNewline state of - Left i -> if y == 0 then Left i else Right y - Right{} -> Right y - , _lstate_addSepSpace = Just $ case _lstate_curYOrAddNewline state of - Left{} -> if y == 0 then x else _lstate_indLevelLinger state + x - Right{} -> _lstate_indLevelLinger state + x - } - else do - mSet state - { _lstate_curYOrAddNewline = case _lstate_curYOrAddNewline state of - Left i -> if y == 0 then Left i else Right y - Right{} -> Right y - , _lstate_addSepSpace = Just - $ if y == 0 then x else _lstate_indLevelLinger state + x - , _lstate_commentCol = Just $ case _lstate_curYOrAddNewline state of - Left i -> i + fromMaybe 0 (_lstate_addSepSpace state) - Right{} -> lstate_baseY state - } + mSet state + { _lstate_curYOrAddNewline = case _lstate_curYOrAddNewline state of + Left i -> if y == 0 then Left i else Right y + Right{} -> Right y + , _lstate_addSepSpace = if Data.Maybe.isJust (_lstate_commentCol state) + then Just $ case _lstate_curYOrAddNewline state of + Left{} -> if y == 0 then x else _lstate_indLevelLinger state + x + Right{} -> _lstate_indLevelLinger state + x + else Just $ if y == 0 then x else _lstate_indLevelLinger state + x + , _lstate_commentCol = Just $ case _lstate_commentCol state of + Just existing -> existing + Nothing -> case _lstate_curYOrAddNewline state of + Left i -> i + fromMaybe 0 (_lstate_addSepSpace state) + Right{} -> lstate_baseY state + } + -- | does _not_ add spaces to again reach the current base column. layoutWriteNewline