[GHC] #9573: Add warning for invalid digits in integer literals
GHC
ghc-devs at haskell.org
Wed Sep 10 15:33:30 UTC 2014
#9573: Add warning for invalid digits in integer literals
-------------------------------------+-------------------------------------
Reporter: vlopez | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 7.10.1
Component: Compiler (Parser) | Version: 7.9
Keywords: parsing, integer, | Operating System:
octal, binary, hexadecimal, | Unknown/Multiple
Architecture: Unknown/Multiple | Type of failure:
Difficulty: Difficult (2-5 | None/Unknown
days) | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------------+-------------------------------------
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.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9573>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list