Skip to content

Bug in the new stimes size check #633

Description

@meooow25

text/src/Data/Text.hs

Lines 379 to 385 in 1994b13

stimes howManyTimes
| howManyTimes < 0 = P.error "Data.Text.stimes: given number is negative!"
| otherwise =
let howManyTimesInt = P.fromIntegral howManyTimes :: Int
in if P.fromIntegral howManyTimesInt == howManyTimes
then replicate howManyTimesInt
else P.error "Data.Text.stimes: given number does not fit into an Int!"

It is possible to go a to Int to a losslessly but have a different numeric value than the Int. Word is the most common example of such a type.

So we currently get incorrect results. As an example,

  stimes (maxBound :: Word) "a"
-- ✅ fromIntegral (fromIntegral (maxBound :: Word) :: Int) == (maxBound :: Word)
= replicate (-1) "a"
= ""

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions