Text.Megaparsec.Byte.Lexer.decimal does not range-check
jchia opened this issue · 2 comments
ghci> import Text.Megaparsec
ghci> import Text.Megaparsec.Byte.Lexer
ghci> parse (decimal @() @ByteString @_ @Word16) "" "65536"
Right 0
Reasonably, a parse error is expected, although from the type constraint (absence of Bounded
), it could be thoughtfully inferred that range check is impossible.
Text.Megaparsec.Char.Lexer.decimal
, other functions like binary
and other bounded integral types are likely similarly affected.
Float
also has problems: #479
attoparsec has a similar issue: haskell/attoparsec#211
If the behavior is not fixed at least the user needs to be made more aware that overflow is not checked, perhaps in the documentation.
Fixing the behavior will likely slow down parsing and hurt benchmarks, but proper benchmark reports should point out cases of comparing apples with oranges (a parser that does range-check and another that does not).
Thanks for the report. I'm going to add a warning about this to the docs.