
#9573: Add warning for invalid digits in integer literals -------------------------------------+------------------------------------- Reporter: vlopez | Owner: vlopez Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.9 (Parser) | Keywords: parsing, integer, Resolution: | octal, binary, hexadecimal, Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Difficult (2-5 Type of failure: | days) None/Unknown | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by vlopez): * owner: => vlopez Old description:
In its latest version, GHC can parse binary (with `-XBinaryLiterals`), octal and hexadecimal literals:
{{{#!hs
0b101010 0o52 0x2A }}}
Currently, the parser/lexer reads digits from the input as long as they are valid for the specified radix. All subsequent digits are interpreted as a new, separate token.
If the user uses a digit which isn't valid for the radix, it may be reported with a non-obvious error message, or interpreted in surprising ways:
{{{#!hs
:t 0o567 0o576 :: Num a => a :t 0o5678 0o5678 :: (Num (a -> t), Num a) => t Prelude> :t 0x1bfah
<interactive>:1:7: Not in scope: ‘h’
replicate 0o5678 [8,8,8,8,8,8,8... }}}
We suggest warning the user when a literal of this sort is written, while respecting any other error messages and the original behaviour.
More specifically, the parser or lexer would give a warning if a token starting with an alphanumeric character is found immediately after a numeric literal, without a blank between them.
New description: In its latest version, GHC can parse binary (with `-XBinaryLiterals`), octal and hexadecimal literals: {{{#!hs
0b101010 0o52 0x2A }}}
Currently, the parser/lexer reads digits from the input as long as they are valid for the specified radix. All subsequent digits are interpreted as a new, separate token. If the user uses a digit which isn't valid for the radix, it may be reported with a non-obvious error message, or interpreted in surprising ways: {{{#!hs
:t 0o567 0o576 :: Num a => a :t 0o5678 0o5678 :: (Num (a -> t), Num a) => t :t 0x1bfah
<interactive>:1:7: Not in scope: ‘h’
replicate 0o5678 [8,8,8,8,8,8,8... }}}
We suggest warning the user when a literal of this sort is written, while respecting any other error messages and the original behaviour. More specifically, the parser or lexer would give a warning if a token starting with an alphanumeric character is found immediately after a numeric literal, without a blank between them. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9573#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler