Skip to content

Add warning for invalid digits in integer literals

In its latest version, GHC can parse binary (with -XBinaryLiterals), octal and hexadecimal literals:

> 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:

> :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.

Edited by vlopez
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information