Skip to content

Commit

Permalink
Handle invarient inside unsafeTextWithLength
Browse files Browse the repository at this point in the history
  • Loading branch information
reixn committed Jul 20, 2022
1 parent ae1d2a6 commit 4104207
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion prettyprinter/src/Prettyprinter/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ unsafeTextWithoutNewlines text = case T.uncons text of
-- unsafeTextWithLength "😃" (realLength "😃")
-- @
unsafeTextWithLength :: Text -> Int -> Doc ann
unsafeTextWithLength txt l = Text l txt
unsafeTextWithLength txt l | T.null txt = Empty
| l == 1 && T.length txt == 1 = Char (T.head txt) -- no wide character or control
| otherwise = Text l txt

-- | The empty document behaves like @('pretty' "")@, so it has a height of 1.
-- This may lead to surprising behaviour if we expect it to bear no weight
Expand Down

0 comments on commit 4104207

Please sign in to comment.