megaparsec
megaparsec copied to clipboard
Text.Megaparsec.Byte.Lexer.decimal does not range-check
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: https://github.com/mrkkrp/megaparsec/issues/479
attoparsec has a similar issue: https://github.com/haskell/attoparsec/issues/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.
It looks like I added a note about this in 2a460744305c60d34b47296681108cb354172530 but forgot to close the issue.