diagnostic codes / Lexer
E0003 bad-number-literal
A radix prefix was given no digits.
E0003bad-number-literalforms: 123, 0x1F, 0o17, 0b1010, 3.14, 1e-9
| severity | error |
|---|---|
| band | Lexer |
| in the v0 bootstrap | emitted |
| explain | ralt explain E0003 |
`0x`, `0o` and `0b` must be followed by at least one digit of that radix. The lexer checks the prefix before it reads the body, so `0x;` is this error rather than a zero followed by an identifier.
What it looks like
e0003.tp
use tier core; fn main() -> i32 { print_i32(0x); return 0; }
ralt check e0003.tp e0003.tp:4:15: error: empty number literal after 0x/0o/0b [E0003 bad-number-literal] forms: 123, 0x1F, 0o17, 0b1010, 3.14, 1e-9
What to do
- Add at least one digit: `0x0`, `0o0`, `0b0`.
- Digits of the wrong radix stop the literal early rather than report this code; `0b102` lexes as `0b10` followed by a separate `2`, and the parser then reports the stray token.
- Underscores are allowed between digits: `0xFF_FF` is 65535.
Why the code exists
The message names the four legal forms, so the whole number grammar is in the diagnostic. An agent does not need to fetch a second page to repair the literal.
What ralt explain says
ralt explain E0003 E0003 severity: error name: bad-number-literal hint: forms: 123, 0x1F, 0o17, 0b1010, 3.14, 1e-9
Related
- Literals and names /docs/reference/literals