Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,14 @@ startsWithLine sds = case sds of
SAnnPop s -> startsWithLine s
_ -> False

-- | Test whether a docstream is 'SFail', ignoring any annotations.
isFail :: SimpleDocStream ann -> Bool
isFail sds = case sds of
SFail -> True
SAnnPush _ s -> isFail s
SAnnPop s -> isFail s
_ -> False


-- $
-- >>> import qualified Data.Text.IO as T
Expand Down Expand Up @@ -1794,6 +1802,7 @@ layoutWadlerLeijen
-> SimpleDocStream ann -- ^ Choice B.
-> SimpleDocStream ann -- ^ Choice A if it fits, otherwise B.
selectNicer (FittingPredicate fits) lineIndent currentColumn x y
| isFail x = y
Copy link
Copy Markdown
Collaborator Author

@sjakobi sjakobi Nov 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering whether we need to worry about SFail appearing elsewhere than the beginning of a left Union branch. At least fuse doesn't seem to "hide" the Fail in a (Union Fail x) though:

https://github.com/quchen/prettyprinter/blob/4d51362d7ea8bca0fe9e7ffec2ccd8fcd0065c0d/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs#L1407

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isFail is False if the document fails, but that’s the same thing the two fitting predicates (for layoutPretty and layoutSmart) yield. What does the explicit isFail clause change?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've explained this in #91 (comment).

The short version is that both fitting predicates shortcut to True when the maxWidth is Nothing – which is the case with Unbounded layout options.

| fits pWidth minNestingLevel availableWidth x = x
| otherwise = y
where
Expand Down
8 changes: 8 additions & 0 deletions prettyprinter/test/Testsuite/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ tests = testGroup "Tests"
, testCase "Preserve leading indentation"
removeTrailingWhitespacePreserveIndentation
]
, testCase "Unbounded layout of `group`ed Line fails (#91)"
regressionUnboundedGroupedLine
]
]

Expand Down Expand Up @@ -296,3 +298,9 @@ removeTrailingWhitespacePreserveIndentation
= let sdoc :: SimpleDocStream ()
sdoc = SLine 2 (SChar 'x' SEmpty)
in assertEqual "" sdoc (removeTrailingWhitespace sdoc)

regressionUnboundedGroupedLine :: Assertion
regressionUnboundedGroupedLine
= let sdoc :: SimpleDocStream ()
sdoc = layoutPretty (LayoutOptions Unbounded) (group hardline)
in assertEqual "" (SLine 0 SEmpty) sdoc